2017-06-13 94 views
0

使用板載Authentication systemlaravel 5應用程序進行操作。用戶可以註冊並登錄。有一項功能可以禁用某些用戶。結果將是禁用用戶將無法登錄,直到他們被啓用。限制某些註冊用戶在Laravel應用程序中登錄

我有一個字段activeusers表。

我經歷了LoginController和AuthenticatesUsers特質。但沒有得到任何線索,我可以檢查用戶是否被禁用。

任何線索或幫助?

編輯:在日誌中使用的AuthenticatesUsers特質

附: 下面的代碼來了不是我寫的laravel

trait AuthenticatesUsers 
{ 
    use RedirectsUsers, ThrottlesLogins; 

    public function showLoginForm() 
    { 
     return view('auth.login'); 
    } 

    public function login(Request $request) 
    { 
     $this->validateLogin($request); 

     if ($this->hasTooManyLoginAttempts($request)) { 
      $this->fireLockoutEvent($request); 

      return $this->sendLockoutResponse($request); 
     } 

     if ($this->attemptLogin($request)) { 
      return $this->sendLoginResponse($request); 
     } 

     $this->incrementLoginAttempts($request); 

     return $this->sendFailedLoginResponse($request); 
    } 

    protected function validateLogin(Request $request) 
    { 
     $this->validate($request, [ 
      $this->username() => 'required', 'password' => 'required', 
     ]); 
    } 

    protected function attemptLogin(Request $request) 
    { 
     return $this->guard()->attempt(
      $this->credentials($request), $request->has('remember') 
     ); 
    } 

    protected function credentials(Request $request) 
    { 
     return $request->only($this->username(), 'password'); 
    } 

    protected function sendLoginResponse(Request $request) 
    { 
     $request->session()->regenerate(); 

     $this->clearLoginAttempts($request); 

     return $this->authenticated($request, $this->guard()->user()) 
       ?: redirect()->intended($this->redirectPath()); 
    } 

    protected function authenticated(Request $request, $user) 
    { 
     // 
    } 

    protected function sendFailedLoginResponse(Request $request) 
    { 
     return redirect()->back() 
      ->withInput($request->only($this->username(), 'remember')) 
      ->withErrors([ 
       $this->username() => Lang::get('auth.failed'), 
      ]); 
    } 

    public function username() 
    { 
     return 'email'; 
    } 

    public function logout(Request $request) 
    { 
     $this->guard()->logout(); 

     $request->session()->flush(); 

     $request->session()->regenerate(); 

     return redirect('/'); 
    } 

    protected function guard() 
    { 
     return Auth::guard(); 
    } 
} 
+0

共享代碼使用的是驗證用戶身份 –

+0

@GuyS請參閱編輯的問題。 – MASh

+0

請看這裏https://laracasts.com/discuss/channels/laravel/how-to-add-extra-logic-on-login-condition-in-laravel-52 –

回答

0

你可以不喜歡它

protected function credentials(Request $request) 
    { 
     $c = $request->only($this->username(), 'password'); 
     return array_merge($c, ['active' => true]); 
    } 

欲瞭解更多信息,請訪問https://laracasts.com/discuss/channels/laravel/how-to-add-extra-logic-on-login-condition-in-laravel-52

+0

需要添加'use Illuminate \ Http \請求'沿着這個方法覆蓋。好的解決方案 – MASh

+0

@MASh請讓我知道你的改變,所以我可以把它們放在這裏爲未來OP的... :) –

相關問題