Quantcast
Channel: Login only if user is active using Laravel - Stack Overflow
Viewing all articles
Browse latest Browse all 25

Answer by Bikalpa for Login only if user is active using Laravel

$
0
0

LARAVEL 8
I have a column in User Table with value 1 and 0. Here 1 is Active and 0 is Inactive.
Add these lines in

/vendor/laravel/ui/auth-backend/AuthenticatesUsers.php

    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 (method_exists($this, 'hasTooManyLoginAttempts') &&        $this->hasTooManyLoginAttempts($request)) {        $this->fireLockoutEvent($request);        return $this->sendLockoutResponse($request);    }  //ADD THIS SECTION ONLY  //SECTION STARTS  // CHECK IF USER EXISTS IN OUR USER TABLE.  if ($this->guard()->validate($this->credentials($request))) {    //IF USER EXISTS, FIND USER USING EMAIL FROM REQUEST    $user = User::where('email', $request->email)->first();    //CHECK STATUS OF USER (HERE, 1 = ACTIVE & 0 = INACTIVE)    if ($user->status===0) {        //THROW ERROR WITH CUSTOM MESSAGE        throw ValidationException::withMessages([$this->username() => __('User account has been deactivated.')]);    }  }  //SECTION ENDS    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 all articles
Browse latest Browse all 25

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>