在我的应用程序中,我需要通过两种方式检查用户身份验证,首先是用户名和密码(两者都是数据库字段),cake php已经通过给出了这个
$this->Auth->fields = array(
'username' => 'username',
'password' => 'password'
);
NOw MY需要的是,如果在第一种情况下用户无法进行身份验证,则检查用户名和放弃密码之间的用户数据(两者都是数据库字段)为此,我如何使用Auth组件字段?我试过:
else
{
$this->Auth->fields = array(
'username' => 'username',
'password' => 'forgot_password'
);
$this->Auth->login();
}
但这并没有奏效。。还有别的办法吗?我需要两种类型的交叉检查条件,就像其他条件一样。
您应该使用$this->Auth->constructAuthenticate();
。
<?php
function login()
{
if ($this->request->is('post'))
{
if (!$this->Auth->login())
{
$this->Auth->authenticate = array('Form' => array('fields' => array('username' => 'username',
'password' => 'forgot_password')));
$this->Auth->constructAuthenticate();
if ($this->Auth->login())
{
//Your message here
//redirect to further pages
}
else
{
//redirect to login page
}
}
}
}