public function indexAction()
 {
     $callback = $this->params()->fromQuery('callback');
     if (!$callback && $this->getRequest()->getServer('HTTP_REFERER')) {
         $callback = $this->getRequest()->getServer('HTTP_REFERER');
     }
     $callback = $callback ? $callback : '/';
     $model = new ViewModel();
     $auth = Auth::factory();
     $auth->getAuthStorage()->clear();
     $this->cookie()->clear('realm');
     return $this->redirect()->toUrl($callback);
 }
Beispiel #2
0
 public function loginByPassword($loginIdentity, $password)
 {
     $identityType = 'userName';
     if (is_numeric($loginIdentity)) {
         $identityType = 'mobile';
     } else {
         $validator = new \Zend\Validator\EmailAddress();
         if ($validator->isValid($loginIdentity)) {
             $identityType = 'email';
         }
     }
     switch ($identityType) {
         case 'email':
             $dbWhere = array('email' => $loginIdentity);
             $identityColumn = 'email';
             break;
         case 'mobile':
             $dbWhere = array('mobile' => $loginIdentity);
             $identityColumn = 'mobile';
             break;
         default:
             $dbWhere = array('userName' => $loginIdentity);
             $identityColumn = 'userName';
     }
     $auth = Auth::factory();
     $user = $this->getItem()->getDataClass()->columns(array('id', 'salt', 'userName'))->where($dbWhere)->find('one');
     if (!$user || !$user['id']) {
         return $this->loginResult = new Result(Result::FAILURE_IDENTITY_NOT_FOUND, $loginIdentity, array(Result::FAILURE_IDENTITY_NOT_FOUND => 'A record with the supplied identity could not be found.'));
     }
     if (!$user['salt']) {
         throw new \Exception(sprintf('User authention salt not found'));
     }
     $bcrypt = new \Zend\Crypt\Password\Bcrypt();
     $bcrypt->setSalt($user['salt']);
     $password = $bcrypt->create($password);
     $this->loginResult = $loginResult = $auth->getAuthService(array('tableName' => 'user_users', 'identityColumn' => $identityColumn, 'credentialColumn' => 'password'))->getAdapter()->setIdentity($loginIdentity)->setCredential($password)->authenticate();
     if ($loginResult->isValid()) {
         return $this->loginById($user['id']);
     }
     return $loginResult;
 }