diff --git a/application/Bootstrap.php b/application/Bootstrap.php index 2785953..d69631f 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -66,7 +66,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view->headScript()->appendFile('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'); Zend_Locale::setDefault('sv_SE'); - return $view; } @@ -106,7 +105,9 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $router = $this->getResource('front')->getRouter(); - + /* + * Default routes to the default module + */ $router->addRoute('default', new Zend_Controller_Router_Route(':lang/:controller/:action', array( 'lang' => 'sv', @@ -116,8 +117,13 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap ) )); - + /* + * This route allows direct access to IndexController + * without specifying "index" as controller. + * + * Allowed actions need to be specified! + */ $router->addRoute('index', new Zend_Controller_Router_Route( ':lang/:action', array( @@ -125,9 +131,17 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 'module' => 'default', 'controller' => 'index', 'action' => 'index' + ), + array( + 'action' => '(about)' ) )); + + /* + * Route to the blog module + * TODO: This prob. needs changing. + */ $router->addRoute('blog', new Zend_Controller_Router_Route( ':lang/blog/:action/:id', array( @@ -136,9 +150,12 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 'controller' => 'index', 'action' => 'latest', 'id' => '' + ), + array( + 'lang' => '(en|sv)' ) )); - + $router->addRoute('portfolio', new Zend_Controller_Router_Route( ':lang/portfolio/:action', array( @@ -148,6 +165,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 'action' => 'index' ) )); + $router->addRoute('admin', new Zend_Controller_Router_Route( ':lang/admin/:action', diff --git a/application/languages/se.ini b/application/languages/se.ini index cc8710e..bf8a896 100644 --- a/application/languages/se.ini +++ b/application/languages/se.ini @@ -3,6 +3,13 @@ blog = blog about = om fiktiv example = "Det här är ett exempel på %s och %s" +profile information = "profil information" +user information = "användarinformation" +change password = "ändra lösenord" + +firstname = förnamn +lastname = efternamn + email = e-post password = lösenord login = logga in diff --git a/application/models/Mapper/User.php b/application/models/Mapper/User.php index 49ad3f6..35ea3ab 100644 --- a/application/models/Mapper/User.php +++ b/application/models/Mapper/User.php @@ -97,4 +97,18 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract return false; } + + + /** + * Change password + */ + public function changePassword($userId, $password) + { + return $this->_dbTable->update( + array( + 'password' => hash('sha256',$password) + ), + $this->_dbTable->getAdapter()->quoteInto('id = ?',$userId) + ); + } } \ No newline at end of file diff --git a/application/models/User.php b/application/models/User.php index 6a6adf0..7ed6bf9 100644 --- a/application/models/User.php +++ b/application/models/User.php @@ -115,4 +115,19 @@ class User extends Fiktiv_Model_Abstract { return '(' . __CLASS__ . '){' . $this->_email . ' ' . $this->_firstName . ' ' . $this->_lastName . '}'; } + + /** + * Convert object to array + */ + public function toArray() + { + return array( + 'id' => $this->_id, + 'email' => $this->_email, + 'firstName' => $this->_firstName, + 'lastName' => $this->_lastName, + 'isDeleted' => $this->_isDeleted, + 'regDate' => $this->_regDate + ); + } } \ No newline at end of file diff --git a/application/modules/default/controllers/ProfileController.php b/application/modules/default/controllers/ProfileController.php new file mode 100644 index 0000000..476cad5 --- /dev/null +++ b/application/modules/default/controllers/ProfileController.php @@ -0,0 +1,100 @@ +view->form = new Zend_Form(); + + $form->addElement('text', 'email', array( + 'label' => 'u:email', + 'validators' => array(new Zend_Validate_EmailAddress()) + )); + + $form->addElement('text', 'firstName', array( + 'label' => 'u:firstname', + 'validators' => array(new Zend_Validate_Alpha()) + )); + + $form->addElement('text', 'lastName', array( + 'label' => 'u:lastname', + 'validators' => array(new Zend_Validate_Alpha()) + )); + + $form->addElement('password', 'password', array( + 'label' => 'u:password', + 'validators' => array(new Zend_Validate_Alnum()) + )); + + $form->addElement('password', 'passwordConfirm', array( + 'label' => 'u:confirm password', + 'validators' => array(new Zend_Validate_Alnum()) + )); + + $form->addElement('Submit', 'save', array( + 'label' => 'u:save' + )); + + $form->addDisplayGroup( + array( + 'email', + 'firstName', + 'lastName' + ), + 'partOne', + array( + 'legend' => 'u:user information' + ) + ); + + $form->addDisplayGroup( + array( + 'password', + 'passwordConfirm' + ), + 'partTwo', + array( + 'legend' => 'u:change password' + ) + ); + + $form->addDisplayGroup( + array( + 'save' + ), + 'partThree' + ); + + + if ($this->_request->isPost()) { + + $data = $this->_request->getPost(); + + if ($data['password'] !== $data['passwordConfirm']) { + + if (!empty($data['password'])) + $this->view->messages = 'passwords dont match'; + + + } else { + + if ($this->dataService->User->changePassword(Zend_Auth::getInstance()->getIdentity()->id, $data['password'])) + $this->view->messages = 'Lösenordet är ändrat!'; + + unset($data['password']); + } + unset($data['passwordConfirm']); + unset($data['save']); + + $this->dataService->User->update($data, 'id = '.Zend_Auth::getInstance()->getIdentity()->id); + + + } + + + $user = $this->dataService->User->findById(Zend_Auth::getInstance()->getIdentity()->id); + $form->populate($user->toArray()); + + } +} \ No newline at end of file diff --git a/application/modules/default/views/scripts/profile/index.phtml b/application/modules/default/views/scripts/profile/index.phtml new file mode 100644 index 0000000..4669b6d --- /dev/null +++ b/application/modules/default/views/scripts/profile/index.phtml @@ -0,0 +1,12 @@ +
' . $this->messages . '
'; +?> + +Lite text
+ +