Exemplo n.º 1
0
 /**
  * The public challenge action for getting a new password
  *
  * @return void
  */
 public function changepasswordAction()
 {
     $uri = new Digitalus_Uri();
     $uriParams = $uri->getParams();
     if (!isset($uriParams['u']) || !isset($uriParams['c'])) {
         $this->_error;
     } else {
         $userName = $uriParams['u'];
         $challengeId = $uriParams['c'];
         $mdlChallenge = new Login_Challenge();
         if (!$mdlChallenge->isValid($challengeId, $userName)) {
             $this->_error = $this->view->getTranslation('Error: No valid challenge was found. Please try again!');
         } else {
             $changePasswordForm = new User_Form();
             $uri = $this->baseUrl . '/' . Digitalus_Toolbox_Page::getCurrentPageName() . '/p/a/changepassword/u/' . $userName . '/c/' . $challengeId;
             $changePasswordForm->setAction($uri);
             $changePasswordForm->getElement('name')->addValidators(array(array('UsernameExists', true)));
             $changePasswordForm->onlyChangepasswordActionElements(array('legend' => 'Change Password'));
             if ($this->_request->isPost() && $changePasswordForm->isValid($_POST)) {
                 $password = Digitalus_Filter_Post::get('password');
                 $passwordConfirm = Digitalus_Filter_Post::get('password_confirm');
                 $mdlUser = new Model_User();
                 if (!$mdlUser->updatePassword($userName, $password, true, $passwordConfirm)) {
                     $this->_error = $this->view->getTranslation("Error: Your password hasn't been updated!");
                 } else {
                     $mdlChallenge->invalidate($challengeId);
                     $this->_message = $this->view->getTranslation('Your password has been updated successfully!');
                 }
             } else {
                 $this->_message = $this->view->getTranslation('Please type in Your user name and Your new password.');
                 $this->view->form = $changePasswordForm;
             }
         }
     }
     $this->view->error = $this->_error;
     $this->view->message = $this->_message;
 }