Skip to content

Instantly share code, notes, and snippets.

@ixti
Created July 13, 2010 09:00
Show Gist options
  • Select an option

  • Save ixti/473653 to your computer and use it in GitHub Desktop.

Select an option

Save ixti/473653 to your computer and use it in GitHub Desktop.
<?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