Exemplo n.º 1
0
 protected function mockLogin($username)
 {
     $userSessionModel = new UserSessionModel();
     $userSessionModel->setUserId(1);
     $userSessionModel->setName($username);
     $authService = $this->getMock('Zend\\Authentication\\AuthenticationService');
     $authService->expects($this->any())->method('getIdentity')->will($this->returnValue($userSessionModel));
     $authService->expects($this->any())->method('hasIdentity')->will($this->returnValue(true));
     $this->getServiceLocator()->setAllowOverride(true);
     $this->getServiceLocator()->setService('Zend\\Authentication\\AuthenticationService', $authService);
 }
Exemplo n.º 2
0
 /**
  * Performs an authentication attempt
  */
 public function authenticate()
 {
     $userId = $this->getUserIdFromEmailAndPassword();
     if (!$userId) {
         $userId = $this->getUserIdFromUsernameAndPassword();
     }
     if ($userId) {
         $userModel = $this->loadModel('User', $userId);
         $userSessionModel = new UserSessionModel();
         $userSessionModel->setUserId($userId);
         $userSessionModel->setName($userModel->get('name'));
         $result = new Result(Result::SUCCESS, $userSessionModel);
     } else {
         $result = new Result(Result::FAILURE, null, [$this->translate('Login failed.  Please try again.')]);
     }
     return $result;
 }