Пример #1
0
 /**
  * Overridden isValid() method for pre-validation code.
  *
  * @param array $formData data typically from a POST or GET request.
  *
  * @return bool
  */
 public function isValid($formData = array())
 {
     // If a password is given, username is mandatory
     if (isset($formData['password']) && trim($formData['password']) != '') {
         $this->getElement('username')->setRequired(true);
     }
     // If a security question is given, security answer is mandatory
     if (isset($formData['question']) && trim($formData['question']) != '') {
         $this->getElement('answer')->setRequired(true);
     }
     // Check what has been supplied is enough detail to find a single agent user with
     $agentUserManager = new Manager_Core_Agent_User();
     $fuzzySearchResult = $agentUserManager->searchByFuzzyCredentials($formData);
     if (is_string($fuzzySearchResult)) {
         // Agent details can't be found; set form-level error
         $this->addError('A problem occurred: ' . $fuzzySearchResult);
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 /**
  * Password retrieval - generate password reset link.
  *
  * @return void
  */
 public function lostLoginAction()
 {
     $this->_helper->layout->setLayout('login');
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('hl_connect'));
     if ($auth->hasIdentity()) {
         // User is already logged in so just push them into the system
         $this->_redirect('/');
     }
     // Instantiate form definition
     $pageForm = new Connect_Form_LostLogin();
     // Validate form if POSTed
     $request = $this->getRequest();
     if ($request->isPost()) {
         $postData = $request->getPost();
         if ($pageForm->isValid($postData)) {
             try {
                 $agentUserManager = new Manager_Core_Agent_User();
                 $agentUser = $agentUserManager->searchByFuzzyCredentials($postData);
                 // Send password reset link details
                 $success = $agentUserManager->sendPasswordResetLink($agentUser);
                 // Show user confirmation that reset details have been sent
                 $this->_helper->viewRenderer('lost-login-sent');
             } catch (Zend_Exception $e) {
             }
         }
     }
     $this->view->form = $pageForm;
 }