没有使用laravel默认的LoginController如何集成laravel throttle?
这是我的 Controller :
use AuthenticatesUsers;
//function for login
public function login(Request $requests){
$username = $requests->username;
$password = $requests->password;
/**to login using email or username**/
if(filter_var($username, FILTER_VALIDATE_EMAIL)) {
Auth::attempt(['email' => $username, 'password' => $password]);
} else {
Auth::attempt(['username' => $username, 'password' => $password]);
}
if(Auth::check()){
if(Auth::user()->type_user == 0){
return view('users.dashboard');
}
else{
return view('admin.dashboard');
}
}
else{
return Redirect::back()->withInput()->withErrors(['message'=>$login_error],'login');
}
}
我想限制失败的登录,但我似乎无法使用我自己的 Controller 使其工作。你们能帮帮我吗?
最佳答案
在您的方法中添加以下代码。把它放在第一位
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
现在在登录失败的地方添加如下代码。这将增加失败的尝试次数。
$this->incrementLoginAttempts($request);
成功登录后,添加以下代码以使其重置。
$this->clearLoginAttempts($request);
关于php - Laravel:在自定义登录中集成 Throttle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45180537/