Laravel的Auth默认是以邮箱来登录的,怎样改成用户名OR邮箱登录?
多次登录错误显示验证码又怎样实现?(这是YII2的方式)
登录时能以用户名或邮箱登录,当用户名/邮箱或密码错误3次之后要求输入验证码,怎么实现?
我试图重写postLogin方法:
public function postLogin(Request $request)
{
$username = $request->get('username');
$email = $request->get('email');
$password = $request->get('password');
$remeber = $request->get('remember');
//登录表单验证
$validator = Validator::make($request->all(), [
'username' => 'bail|required|min:5|max:30|unique:users',
'password' => 'bail|required|min:8|max:50',
]);
//表单验证失败提示
if ($validator->fails()) {
$errors = $validator->errors()->all();
if (count($errors) > 0) {
Flash::error(implode('<br></br>', $errors));
}
return redirect('/login')
->withInput();
}
//登录验证
if (Auth::attempt(['email' => $username, 'password' => $password])
|| Auth::attempt(['username' => $username, 'password' => $password])) {
Flash('登录成功');
return redirect()->intended($this->redirectPath());
} else {
Flash(Lang::get('auth.failed'), 'error');
return redirect('/login')
->withInput();
}
}<br></br>
结果使用邮箱登录正常,以用户名登录时居然提示:用户名已经存在!
这不是注册用户函数,怎么会有这样的提示?