Laravel有oauth扩展包,可以参考这里:https://phphub.org/topics/1792
目前并没有完全解决,继续求助。
还有,这个路由https://laravist.com/discuss/comment/update
出错了,导致无法编辑。
@JellyBool 登录和注册的问题我解决了,但现在卡在“throttles”(登录锁定)上。
//尝试登录次数过多处理
if ($this->hasTooManyLoginAttempts($request)) {
if ($request->ajax()) {
Flash::error(Lang::get('auth.throttles'));
return response()->json(['lockout_time' => $this->lockoutTime()]);
} else {
Flash::error(Lang::get('auth.throttles'));
return $this->sendLockoutResponse($request);
}
}
这样写并没有返回throttles,而是继续运行,这样就无法阻止恶意用户不断登录了。
另外这个属性protected $lockoutTime是不是设置登录锁定间隔时间的?
@JellyBool 谢谢,另外问下我这个登录函数里面的逻辑是否有问题,为什么以用户名登录会出现“用户名已经存在”?这应该是注册时出现的提示。
解决了,把前面的$validator = Validator::make
里面的|unique:users
删掉就好了。
顺便问下,怎样延长多次登录失败之后的间隔时间?默认的60秒太短了。
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('
', $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();
}
}
结果使用邮箱登录正常,以用户名登录时居然提示:用户名已经存在!
这不是注册用户函数,怎么会有这样的提示?