Esempio n. 1
0
 public function testAuthenticateWithUnverifiedAccount()
 {
     $adapter = new DoctrineAdapter();
     $this->_authUser->setActive(0);
     $result = $adapter->setIdentity('Admin')->setCredential('password')->authenticate();
     $this->assertTrue($result instanceof AuthResult);
     $this->assertEquals(AuthResult::FAILURE_REQUIRES_EMAIL_VERIFICATION, $result->getCode());
 }
Esempio n. 2
0
 /**
  * Process login using form values
  *
  * @param Application_Form_UserLogin $form
  * @return void
  */
 private function _processAuth(\Application_Form_UserLogin $form)
 {
     $values = $form->getValues();
     $adapter = new DoctrineAuthAdapter();
     $adapter->setIdentity($values['username'])->setCredential($values['password']);
     $auth = Zend_Auth::getInstance();
     $result = $auth->authenticate($adapter);
     switch ($result->getCode()) {
         case AuthResult::FAILURE_IDENTITY_NOT_FOUND:
         case AuthResult::FAILURE_ACCOUNT_LOCKED:
             $message = "Failure - Identity not found";
             break;
         case AuthResult::FAILURE_CREDENTIAL_INVALID:
             $message = "Failure - Credential invalid";
             break;
         case AuthResult::FAILURE_REQUIRES_EMAIL_VERIFICATION:
             $message = "Failure - Account requires email verification";
             break;
         case AuthResult::SUCCESS:
             $message = "Success";
             break;
             // @codeCoverageIgnoreStart
         // @codeCoverageIgnoreStart
         default:
             $message = "Failure - Unknown error";
             // @codeCoverageIgnoreEnd
     }
     $form->addErrorMessage($message);
     if ($result->isValid()) {
         $user = $adapter->getUser();
         session_id();
         $siteDomain = Zend_Registry::get('siteDomain');
         // Track login event
         UserLoginEventService::create(array('user' => $user, 'date' => new DateTime(), 'ip' => $this->getRequest()->getServer('REMOTE_ADDR')));
         $auth->getStorage()->write($user->getId());
         // Set auth cookie
         if (!Zend_Session::$_unitTestEnabled) {
             // @codeCoverageIgnoreStart
             $authCookieName = Zend_Registry::get('config')->session->auth->name;
             $cookieParams = session_get_cookie_params();
             setcookie($authCookieName, 1, 0, $cookieParams['path'], $cookieParams['domain'], $cookieParams['secure'], true);
         }
         // @codeCoverageIgnoreEnd
         return true;
     }
     return false;
 }