Example #1
0
 public function loginAction()
 {
     if ($this->_helper->member()) {
         $this->redirect(Config::get('routes')->profile);
     }
     if ($this->_request->isPost()) {
         $identity = trim($this->_getParam('email'));
         $password = $this->_getParam('password');
         if (empty($identity) || empty($password)) {
             $this->view->error = $this->translate->_('Wrong email or password');
             return;
         }
         $adapter = new Adapter(Config::get('auth')->adapter);
         $adapter->setIdentity($identity)->setCredential($password);
         $result = $this->auth->authenticate($adapter);
         if ($result->isValid()) {
             // TODO handle "remember me"
             if ($this->_getParam('back')) {
                 $this->redirect($this->_getParam('back'));
             }
             $this->redirect(Config::get('routes')->profile);
         }
         switch ($result->getCode()) {
             case \Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
             case \Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
                 $error = $this->translate->_('Wrong email or password');
                 break;
             default:
                 $error = $this->translate->_('Unexpected error occurred');
                 break;
         }
         $this->view->error = $error;
     }
 }
Example #2
0
 public static function login($identity, $password)
 {
     $adapter = new Adapter(Config::get('auth')->adapter);
     $adapter->setIdentity($identity)->setCredential($password);
     return \Zend_Auth::getInstance()->authenticate($adapter);
 }