1

我正在使用Zend_Auth验证用户凭据并遇到问题。我需要有一个双列标识。这两列是用户名和客户标识符。identityColumn设置和setIdentity()方法不允许这种情况。我尝试通过使用该credentialTreatment设置来完成此操作,但是当我有两个或多个客户的重复用户名时,它只会将zend_auth_credential_match其他客户的用户名计算为 false,而不是过滤掉这些用户。

这是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')

是否需要扩展Zend_Auth模块才能做到这一点?有没有其他人做过并且可以提供一个例子?

谢谢!

4

2 回答 2

5

我想你需要编写自己的子类Zend_Auth_Adapter_DbTable来处理这个问题。

就像是:

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;
  }
}
于 2010-02-16T21:57:01.730 回答
3

最好的方法是编写自己的 Auth 适配器。甚至可能直接扩展 Zend_Auth_Adapter_DbTable。

于 2010-02-16T21:50:46.627 回答