Login only if user is active using Laravel

前端 未结 19 1854
孤城傲影
孤城傲影 2020-11-30 23:26

I\'m currently working on my Laravel app and to prevent spam I decided that only active users are able to login. I\'m currently using Laravel\'s login system just like in La

19条回答
  •  無奈伤痛
    2020-11-30 23:52

    I check user is actived by overwrite sendLoginResponse function in LoginController

    protected function sendLoginResponse(Request $request)
    {
        if($this->guard()->user()->active == 0){
            $this->guard()->logout();
            return redirect()->back()
                ->withInput($request->only($this->username(), 'remember'))
                ->withErrors(['active' => 'User in not activated.']);
        }
    
        $request->session()->regenerate();
    
        $this->clearLoginAttempts($request);
    
        return $this->authenticated($request, $this->guard()->user())
                ?: redirect()->intended($this->redirectPath());
    }
    

提交回复
热议问题