Ejemplo n.º 1
0
 /**
  * Processes the new password and stores in DB
  *
  * @return void
  */
 public function resetpassprocessAction()
 {
     if ($this->getRequest()->isPost()) {
         $password = $this->getRequest()->getPost('password');
         $passwordConfirm = $this->getRequest()->getPost('passwordConfirm');
         $guid = $this->getRequest()->getPost('guid');
         //check valid password
         $passwordLengthValidator = new Zend_Validate_StringLength(array('min' => MIN_PASS_CHAR, 'max' => MAX_PASS_CHAR));
         $alNumValidator = new Zend_Validate_Alnum();
         $error = false;
         if (strcmp($password, $passwordConfirm) != 0) {
             $this->_helper->flashMessenger->addMessage('Your passwords do not match.');
             $error = true;
         }
         if (!$passwordLengthValidator->isValid($password)) {
             if (!$alNumValidator->isValid($password)) {
                 $this->_helper->flashMessenger->addMessage('You password must only consist of letters and numbers.');
                 $error = true;
             } else {
                 $this->_helper->flashMessenger->addMessage('Passwords must be between ' . MIN_PASS_CHAR . ' and ' . MAX_CHAR_PASS . ' characters in length.');
                 $error = true;
             }
         }
         //if validation errors, store data in view
         if ($error) {
             $session = new Zend_Session_Namespace();
             $session->flashMessengerClass = 'flashMessagesRed';
             $session->guid = $guid;
             $this->_redirect('/login/resetpass/id/' . $guid . '/');
         } else {
             //register use and redirect to success page
             $options = $this->getInvokeArg('bootstrap')->getOptions();
             $salt = $options['password']['salt'];
             $user = new Model_DbTable_Users();
             $passwordReset = new Model_DbTable_PasswordReset();
             $id = $passwordReset->getID($guid);
             $result = $user->changePassword($id, sha1($password . $salt));
             $username = $user->getUsername($id);
             $email = $user->getEmail($id);
             if ($result != null) {
                 $passwordReset->delete($passwordReset->getAdapter()->quoteInto('guid = ?', $guid));
                 //send email with username and password.
                 $html = '<p>Your new login information is below:</p>' . '<p>Username: '******'</p>' . '<p>Password: '******'</p>';
                 $text = "Your new login information is below:\n" . "Username: {$username} . \nPassword: {$password} \n";
                 $this->sendMail($username, $email, $html, $text, 'Account Information');
                 $session = new Zend_Session_Namespace();
                 $session->flashMessengerClass = 'flashMessagesGreen';
                 $this->_helper->flashMessenger->addMessage('Your password has been successfully reset.');
                 $this->_redirect('/login/index/');
             } else {
                 $session = new Zend_Session_Namespace();
                 $session->flashMessengerClass = 'flashMessagesRed';
                 $this->_helper->flashMessenger->addMessage('Your password could not be reset.');
                 $this->_helper->redirector->gotoRoute(array(), 'forgot-password');
             }
         }
     } else {
         $this->_helper->redirector->gotoRoute(array(), 'forgot-password');
     }
 }