Created
July 13, 2010 09:00
-
-
Save ixti/473653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class RS_Auth_Adapter implements Zend_Auth_Adapter_Interface | |
| { | |
| const NOT_FOUND_MSG = 'Account not found'; | |
| const BAD_PW_MSG = 'Password in invalid'; | |
| protected $user = null; | |
| protected $username = ''; | |
| protected $password = ''; | |
| public function __construct($username, $password) | |
| { | |
| $this->username = $username; | |
| $this->password = $password; | |
| } | |
| public function authenticate() | |
| { | |
| try { | |
| $this->user = Model_User::authenticate($this->username, $this->password); | |
| return $this->createResult(Zend_Auth_Result::SUCCESS); | |
| } catch(Exception $e) { | |
| if (Model_User::WRONG_PW == $e->getMessage()) { | |
| $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID; | |
| $msgs = array(self::BAD_PW_MSG); | |
| } elseif (Model_User::NOT_FOUND == $e->getMessage()) { | |
| $code = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND; | |
| $msgs = array(self::NOT_FOUND_MSG); | |
| } else { | |
| $code = Zend_Auth_Result::FAILURE; | |
| $msgs = array(); | |
| } | |
| return $this->createResult($code, $messages); | |
| } | |
| } | |
| private function createResult($code, $messages = array()) | |
| { | |
| return new Zend_Auth_Result($code, $this->user, $messages); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment