/** * 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; }
/** * Set user credentials * * @param string $identity * @param string $credentials * * @return Default_Model_Mapper_User */ public function setCredentials($identity, $credentials) { $this->_mapper->setCredentials($identity, $credentials); }