我的应用使用标准的Auth模块使用电子邮件和密码组合登录。
我需要对其进行修改,以便用户可以输入电子邮件或带有密码的唯一7位数代码。
在Laravel文档中,我找到了这段代码。
if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
// The user is active, not suspended, and exists.
}
我已经修改了表以包含正确的代码,但还没有弄清楚如何进行身份验证。
之前是否还有其他人遇到此类问题?提前谢谢。
答案 0 :(得分:1)
在AuthController
覆盖(添加)getCredentials
方法内,如下所示:
protected function getCredentials(Request $request)
{
$login = filter_var($request->input('login'), FILTER_VALIDATE_EMAIL) ? 'email' : 'digits'; //Change digits to your table column name
return [
$login => $request->input('login'),
'password' => $request->input('password') //you can add any db field here e.g: "active" => 1
];
}
要进行验证,您还需要覆盖validateLogin
:
protected function validateLogin(Request $request)
{
$this->validate($request, [
'login' => 'required', 'password' => 'required',
]);
}
不要忘记在视图中将输入名称更改为login
!
答案 1 :(得分:0)
我相信Laravel身份验证'电子邮件' field只是一个字符串,并且没有强制验证字段作为电子邮件(视图模板字段实现除外)。因此,您可以轻松地将该字段替换为另一个用户名'您选择的字段,并在创建过程中对其进行自己的验证。
请注意身份验证页面https://laravel.com/docs/5.1/authentication
中的摘录UIActionSheet