Ejemplo n.º 1
0
Archivo: User.php Proyecto: kokx/Firal
 /**
  * Log the user in
  *
  * @param array $data
  *
  * @return bool
  */
 public function login(array $data)
 {
     $form = $this->getLoginForm();
     if (!$form->isValid($data)) {
         return false;
     }
     $this->_mapper->setCredentials($form->getValue('username'), $form->getValue('password'));
     $auth = Zend_Auth::getInstance();
     Firal_Plugin::getDefaultDispatcher()->trigger(new Firal_Event($form, 'default.user.login'));
     $result = $auth->authenticate($this->_mapper);
     // invalid result
     if (!$result->isValid()) {
         switch ($result->getCode()) {
             case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
                 $form->getElement('username')->setErrors(array("There is no '{$form->getValue('username')}' user."));
                 break;
             case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
                 $form->getElement('password')->setErrors(array("Wrong password."));
                 break;
         }
         $auth->getStorage()->write($result->getIdentity());
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Set user credentials
  *
  * @param string $identity
  * @param string $credentials
  *
  * @return Default_Model_Mapper_User
  */
 public function setCredentials($identity, $credentials)
 {
     $this->_mapper->setCredentials($identity, $credentials);
 }