public function fetchpasswordAction() { if (Zend_Auth::getInstance()->hasIdentity()) { $this->_redirect($this->getUrl()); } $errors = array(); $action = $this->getRequest()->getQuery('action'); if ($this->getRequest()->isPost()) { $action = 'submit'; } switch ($action) { case 'submit': $username = trim($this->getRequest()->getPost('username')); if (strlen($username) == 0) { $errors['username'] = '******'; } else { $user = new DatabaseObject_User($this->db); if ($user->load($username, 'username')) { $user->fetchPassword(); $url = $this->getUrl('fetchpassword') . '?action=complete'; $this->_redirect($url); } else { $errors['username'] = '******'; } } break; case 'complete': break; case 'confirm': $id = $this->getRequest()->getQuery('id'); $key = $this->getRequest()->getQuery('key'); $user = new DatabaseObject_User($this->db); if (!$user->load($id)) { $errors['confirm'] = 'Error confirming new password'; } else { if (!$user->confirmNewPassword($key)) { $errors['confirm'] = 'Error confirming new password'; } } break; } $this->breadcrumbs->addStep('Login', $this->getUrl('login')); $this->breadcrumbs->addStep('Fetch Password'); $this->view->errors = $errors; $this->view->action = $action; }
/** * fetch forgotten password page: Users can request a password reset by givin their username, a new password is created and sent * to user email address. Users must also activate the new password on this page by clicking the activation link in the email. * * @param String $action Defines wheather the user is asking for reset or activating the new password * @param String $username Username whose password will be changed * @param int $id Used in password activation, this is the id of user whose new password wil l be activated * @param int $key Md5 hash to confirm that user is following the link in activation email */ public function fetchpasswordAction() { // if a user's already logged in, send them to their account home page if (Zend_Auth::getInstance()->hasIdentity()) { $this->_redirect('/account'); } // initialize the error array $errors = array(); $action = $this->getRequest()->getQuery('action'); if ($this->getRequest()->isPost()) { $action = 'submit'; } // check is the user requesting password reset or activating new password switch ($action) { case 'submit': // request new password // get username form post $username = trim($this->getRequest()->getPost('username')); // check that username is not empty if (strlen($username) == 0) { $errors['username'] = '******'; } else { $user = new DatabaseObject_User($this->db); // load user data if ($user->load($username, 'username')) { // create the new password and send email to user $user->fetchPassword($this->view->language); // redirect user $url = '/account/fetchpassword?action=complete'; $this->_redirect($url); } else { $errors['username'] = '******'; } } break; case 'complete': // if user submitted the request password form // nothing to do, show message in view break; // activate new password // activate new password // activate new password // activate new password case 'confirm': $id = $this->getRequest()->getQuery('id'); $key = $this->getRequest()->getQuery('key'); $user = new DatabaseObject_User($this->db); // load user data if (!$user->load($id)) { $errors['confirm'] = 'Error confirming new password'; } else { if (!$user->confirmNewPassword($key)) { $errors['confirm'] = 'Error confirming new password'; } } break; } // inject the possible errors and the action to view $this->view->errors = $errors; $this->view->action = $action; }
public function fetchpasswordAction() { //if a user's already loged in, send them to the thier account home page if (Zend_Auth::getInstance()->hasIdentity()) { $this->_redirect('/account'); } $errors = array(); $action = $this->getRequest()->getQuery('action'); if ($this->getRequest()->isPost()) { $action = 'submit'; } switch ($action) { case 'submit': $username = trim($this->getRequest()->getPost('username')); if (strlen($username) == 0) { $errors['username'] = '******'; } else { $user = new DatabaseObject_User($this->db); if ($user->load($username, 'username')) { $user->fetchPassword(); $url = '/account/fetchpassword?action=complete'; $this->_redirect($url); } else { $errors['username'] = '******'; } } break; case 'complete': //nothing to do break; case 'confirm': $id = $this->getRequest()->getQuery('id'); $key = $this->getRequest()->getQuery('key'); $user = new DatabaseObject_User($this->db); if (!$user->load($id)) { echo "here at bad load"; $errors['confirm'] = 'Error confirming new password at badload'; } elseif (!$user->confirmNewPassword($key)) { echo "here at bad key"; $errors['confirm'] = 'Error confirming new password at bad key'; } break; } $this->view->errors = $errors; $this->view->action = $action; }