tegi
unread,Oct 27, 2010, 3:56:31 PM10/27/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to flextrine
i created zend_auth_adapter for flextrine (doctrine)
/**
* Doctrine auth adapter
*/
class DoctAuthAdapter extends \Flextrine\AbstractFlextrineService
implements Zend_Auth_Adapter_Interface
{
/**
* table name
*
* @var string
*/
private $_table;
/**
* The field name which will be the identifier (username...)
*
* @var string
*/
private $_identityCol;
/**
* The field name which will be used for credentials (password...)
*
* @var string
*/
private $_credentialCol;
/**
* Actual identity value (my_all_known_username)
*
* @var string
*/
private $_identity;
/**
* Actual credential value (my_secret_password)
*
* @var string
*/
private $_credential;
/**
* construct
* @param string $tableName auth table name
* @param string $identityCol identity column name
* @param string $credentialCol password column name
*/
public function __construct($table, $identityCol, $credentialCol)
{
//Assign the column names...
$this->_table = $table;
$this->_credentialCol = $credentialCol;
$this->_identityCol = $identityCol;
}
/**
* @param string $identity
*/
public function setIdentity($identity)
{
$this->_identity = $identity;
}
/**
* @param string $credential
*/
public function setCredential($credential)
{
$this->_credential = $credential;
}
/**
* @return Zend_Auth_Result
*/
public function authenticate()
{
$criteria = array(
$this->_identityCol => $this->_identity,
$this->_credentialCol => $this->_credential
);
$result = $this->loadBy($this->_table, $criteria, "eager");
return new Zend_Auth_Result($result[0]->id ?
Zend_Auth_Result::SUCCESS : Zend_Auth_Result::FAILURE, $result[0]-
>id ? $result[0] : null);
}
}
and then call from FlextrineService:
/**
* login user
* @param username
* @param password
* @return boolean
*/
public function loginUser($email, $password)
{
$authAdapter = new DoctAuthAdapter("Users", "email", "password");
$authAdapter->setIdentity($email);
$authAdapter->setCredential($password);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
return ($result->isValid()) ? true : false;
}