Esempio n. 1
0
 /**
  * Atempts to authenticate
  *
  * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     if (null !== ($user = UserService::findOneByUsername($this->identity))) {
         if (!UserService::verifyPassword($user, $this->credential)) {
             $this->authResultInfo['code'] = AuthResult::FAILURE_CREDENTIAL_INVALID;
             $this->authResultInfo['messages'][] = 'Supplied credential is invalid.';
         } elseif (!$user->getActive()) {
             $this->authResultInfo['code'] = AuthResult::FAILURE_REQUIRES_EMAIL_VERIFICATION;
             $this->authResultInfo['messages'][] = 'User account requires email address verification.';
         } elseif ($user->getLocked()) {
             $this->authResultInfo['code'] = AuthResult::FAILURE_ACCOUNT_LOCKED;
             $this->authResultInfo['messages'][] = 'User account is locked.';
         } else {
             $this->user = $user;
             $user->setLastConnect(new \DateTime());
             UserService::update();
             $this->authResultInfo['code'] = AuthResult::SUCCESS;
             $this->authResultInfo['messages'][] = 'Authentication successful.';
         }
     } else {
         $this->authResultInfo['code'] = AuthResult::FAILURE_IDENTITY_NOT_FOUND;
         $this->authResultInfo['messages'][] = 'Identity not found.';
     }
     return $this->authenticateCreateAuthResult();
 }
Esempio n. 2
0
 public function testProfileActionWithExceptionalValues()
 {
     $user = UserService::findOneByUsername('testuser');
     $profile = $user->getProfile();
     $adminUser = UserService::findOneByUsername('admin');
     $this->assertNotEquals($adminUser->getEmail(), $user->getEmail());
     $this->_loginTestUser();
     $this->redispatch('/user/profile');
     $this->assertNotRedirect();
     $this->assertModule('default');
     $this->assertController('user');
     $this->assertAction('profile');
     $this->getRequest()->setMethod('POST')->setPost(array('email' => $adminUser->getEmail(), 'firstName' => $profile->getFirstName(), 'lastName' => $profile->getLastName()));
     $this->redispatch('/user/profile', false);
     $this->assertNotRedirect();
     $this->assertModule('default');
     $this->assertController('user');
     $this->assertAction('profile');
     $this->assertResponseCode(500);
     $this->assertBodyContains('Application error: UCPA001 - SQLSTATE[23000]: Integrity constraint violation: ', 'Missing application error');
 }
Esempio n. 3
0
 /**
  * Lost password action
  *
  * Allows user to initiate a password reset request.
  *
  * @return void
  */
 public function lostpasswordAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         return $this->getHelper('Redirector')->gotoRoute(array(), 'home');
     }
     $request = $this->getRequest();
     $form = new \Application_Form_UserLostPassword();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $data = $form->getValues();
             try {
                 /*
                 if(null === ($user = UserService::findOneByEmail($data['email']))) {
                   throw new UserControllerException('Sorry. We have no record of that email address');
                 }
                 */
                 if (null !== ($user = UserService::findOneByUsername($data['username']))) {
                     UserService::sendPasswordResetEmail($user);
                 }
                 // Redirect user to home page
                 $this->view->success = 1;
                 //$message = 'An email containing further instructions has been sent to <code>'.$user->getEmail().'</code>.'
                 $message = 'An email containing further instructions has been sent to the email address on file.' . ' Please follow the instructions in the email to reset your password.';
                 $this->_helper->sessionMessenger($message, 'success');
                 return $this->getHelper('Redirector')->gotoRoute(array(), 'home');
             } catch (UserControllerException $e) {
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 $this->view->messages()->addMessage($e->getMessage(), 'error');
             } catch (Exception $e) {
                 // @codeCoverageIgnoreStart
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 $message = 'development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: UCLPA001';
                 $this->view->messages()->addMessage($message, 'error');
                 Logger::err($e->getMessage());
             }
             // @codeCoverageIgnoreEnd
         } else {
             // Submitted form data is invalid
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->success = 0;
         }
     }
     $this->view->form = $form;
 }