Quantcast
Viewing latest article 13
Browse Latest Browse All 25

Answer by thiago tanaka for Login only if user is active using Laravel

Laravel 5.8 tested. Put this code in your LoginController.php and be happy.

public function login(Request $request){    $user = User::where('username',$request->username)->first();    if( $user && !$user->active){        return redirect()->back()->with('error','the user has been desactivated');    }    $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 ($this->hasTooManyLoginAttempts($request)) {        $this->fireLockoutEvent($request);        return $this->sendLockoutResponse($request);    }    if ($this->attemptLogin($request)) {        return $this->sendLoginResponse($request);    }    // 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.    $this->incrementLoginAttempts($request);    return $this->sendFailedLoginResponse($request);}

Viewing latest article 13
Browse Latest Browse All 25

Trending Articles