我想检查用户表的status = 1作为额外验证。我的getAuthAdapter()方法如下所示:
private function getAuthAdapter (){
$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
$authAdapter->setTableName('vi_users')
->setIdentityColumn('email')
->setCredentialColumn('password');
return $authAdapter;
}
我如何更改此内容以包含额外验证?
答案 0 :(得分:2)
我自己遇到了这个问题,我不确定是否可以同时检查另一个列。所以我直截了当地做了这样的事情:
$auth = Zend_Auth::getInstance();
....
if (process($form->getValues())) {
// login credentials are correct, so we now need to check if their account is activated
if ($auth->getIdentity()->active != 1) {
// if not, log them out and tell them to activate
Zend_Auth::getInstance()->clearIdentity();
$output .= "Your account has not yet been activated, please check your email (including spam bin) for the activation link.";
} else {
// if they're active then login is successful
$output .= "You are now logged in";
}
} else {
// username/password wrong
$output .= "Credentials invalid";
}
更新:鉴于奥兰多的答案,看起来你原来要求的是可能的。如果您想区分status
值为'错误'而用户/传递错误,您可以使用我的解决方案。
答案 1 :(得分:1)
您可以执行以下操作:
$adapter = new Zend_Auth_Adapter_DbTable(
$db,
'users',
'username',
'password',
'MD5(?) AND status = 1'
);
其中$ db将是Zend_Db_Table :: getDefaultAdapter()
取自http://framework.zend.com/manual/en/zend.auth.adapter.dbtable.html