Hi there I am trying to redirect any user who tries to login who has a ban_status ! = 0
I am wondering what the best way for me to do this, I was thinking just to log them out and redirect them to a banned page but I only want banned users accessing this page, or adding a error on the form to say 'you are banned' etc. Here is my code currently:
public function login(Request $request) { $this->validateLogin($request);
// 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 ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
$credentials = $this->credentials($request);
if ($this->guard()->attempt($credentials, $request->has('remember'))) {
if ($this->guard()->user()->ban_status === 0) { // Check if the user is banned or not before allowing login
return $this->sendLoginResponse($request);
}
else {
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
return redirect('/banned'); // If the user banned_status is set to 1, then they will be redirected to a banned page.
}
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
if (! $lockedOut) {
$this->incrementLoginAttempts($request);
}
return $this->sendFailedLoginResponse($request);
}