我正在使用cakephp构建应用程序。
我选择了cakephp2.3。
用户将使用'电子邮件'进行身份验证或者'用户名'。
我在Auth组件"范围"中找到了一个选项,但是我们可以设置静态条件。
LIKE: if user is active,, is_active => 1
但是我希望在验证auth组件时应该检查“电子邮件”和“#”。或者'用户名'字段和其他是密码。
有什么办法吗?
答案 0 :(得分:1)
这需要一些代码。您可以通过找到here
的Users / CakeDC插件轻松找到它此插件使用下面的auth组件登录多列。
https://github.com/CakeDC/users/blob/master/Controller/Component/Auth/MultiColumnAuthenticate.php
它还包括如何使用的示例。如果您不想要整个插件,只需将MultiColumnAuthenticate.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'),
)
);
}
}
答案 1 :(得分:0)
根据cakephp文档。
FormAuthenticate
允许您根据表单POST数据对用户进行身份验证。通常这是用户将信息输入
默认AuthComponent
使用FormAuthenticate
你可以试试这个:
// Pass settings in $components array
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email', 'password' => 'password')
)
)
)
);