开发者

Zend Auth With Two Identity Columns

开发者 https://www.devze.com 2022-12-20 03:52 出处:网络
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 s

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消