Zend Auth With Two Identity Columns
I am using Zend_Auth
to validate user credentials and ran into an issue. I need to have a dual column identity. The the two columns are user name and customer identifier. The identityColumn
setting and setIdentity()
methods don't allow for this scenario. I tried to accomplish this by using the cr开发者_如何学PythonedentialTreatment
setting, but when I have a duplicate user name for two or more customers, it merely calculates the zend_auth_credential_match
as false for the other customers rather than filtering those users out.
Here's a sanitized example of the resulting query executed by Zend Auth:
SELECT `users`.*,
(CASE
WHEN `password` = 'password'
AND active = 1
AND customer_id = 1
THEN 1
ELSE 0
END) AS `zend_auth_credential_match`
FROM `users`
WHERE (`username` = 'username')
Is it necessary to extend the Zend_Auth
module to do this? Has anyone else done it and can provide an example?
Thanks!
I would imagine you will need to write your own subclass of Zend_Auth_Adapter_DbTable
to handle this.
Something like:
class My_Auth_Adapter extends Zend_Auth_Adapter_DbTable {
protected $_customerColumn = 'customer_id';
protected $_customerId = false;
public function setCustomerId($id) {
$this->_customerId = $id;
return $this;
}
public function getCustomerId() {
return $this->_customerId!==false?$this->_customerId:'';
}
public function _authenticateCreateSelect() {
$select = parent::_authenticateCreateSelect();
$select->where($this->_zendDb->quoteIdentifier($this->_customerColumn, true)." = ?", $this->getCustomerId());
return $select;
}
}
Best way to do this would be to write your own Auth adapter. Perhaps even extending Zend_Auth_Adapter_DbTable directly.
精彩评论