CAKEPHP2.3:Auth组件,在或中的两列上对用户进行身份验证
我正在使用cakephp构建应用程序 我选择了cakephp2.3 将使用“电子邮件”或“用户名”对用户进行身份验证 我发现了一个带有Auth组件“scope”的选项,但通过它我们可以设置静态条件CAKEPHP2.3:Auth组件,在或中的两列上对用户进行身份验证,php,cakephp,authentication,Php,Cakephp,Authentication,我正在使用cakephp构建应用程序 我选择了cakephp2.3 将使用“电子邮件”或“用户名”对用户进行身份验证 我发现了一个带有Auth组件“scope”的选项,但通过它我们可以设置静态条件 LIKE: if user is active,, is_active => 1 但我希望在验证身份验证组件时,应该检查“email”或“username”字段,另一个是密码 有什么办法吗?这需要一些代码。您可以通过Users/CakeDC-plugin-found轻松找到它 此插件使用下面的
LIKE: if user is active,, is_active => 1
但我希望在验证身份验证组件时,应该检查“email”或“username”字段,另一个是密码
有什么办法吗?这需要一些代码。您可以通过Users/CakeDC-plugin-found轻松找到它 此插件使用下面的auth组件登录多个列 它还包括如何使用的示例。如果您不想要整个插件,可以将multiclumnauthenticate.php复制到app/Controllers/Components/Auth/文件夹中 如果仅复制文件,则在AppController中的beforeFilter方法中,必须写入:
class AppController extends Controller {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->authenticate = array(
'MultiColumn' => array( //With no plugin
'fields' => array(
'username' => 'username',
'password' => 'password'
),
'columns' => array('username', 'email'),
)
);
}
}
根据cakephp文档
FormAuthenticate
允许您根据表单发布数据对用户进行身份验证。通常这是用户输入信息的登录表单
默认情况下,AuthComponent
使用FormAuthenticate
您可以尝试以下方法:
// Pass settings in $components array
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email', 'password' => 'password')
)
)
)
);
我不明白,您为什么添加了以下内容:**返回父项::beforeFilter()**@PankajBadukale这与这个答案无关,但这是cakephp的惯例的一部分。你能指出说这句话的文档吗。因为这会要求输入用户名和电子邮件,而不是用户名和密码。您可以访问以下链接: