Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ZExt_Auth_Adapter implements Zend_Auth_Adapter_Interface
- {
- const NOT_FOUND_MSG = "Account not found";
- const CREDENTIAL_INVALID_MSG = "Password is invalid";
- /**
- *
- * @var Model\User
- */
- protected $user;
- /**
- *
- * @var string
- */
- protected $username = "";
- /**
- *
- * @var string
- */
- protected $password = "";
- public function __construct($username, $password)
- {
- $this->username = $username;
- $this->password = $password;
- }
- /**
- * Performs an authentication attempt
- *
- * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
- * @return Zend_Auth_Result
- */
- public function authenticate()
- {
- try
- {
- $this->user = Models\User::authenticate($this->username, $this->password);
- return $this->createResult(Zend_Auth_Result::SUCCESS);
- }
- catch (Exception $e)
- {
- if ($e->getMessage() == Models\User::CREDENTIAL_INVALID)
- return $this->createResult(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, array(self::CREDENTIAL_INVALID_MSG));
- elseif ($e->getMessage() == Models\User::NOT_FOUND)
- return $this->createResult(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, array(self::NOT_FOUND_MSG));
- }
- }
- private function createResult($code, $messages = array())
- {
- return new Zend_Auth_Result($code, $this->user, $messages);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement