使用板載Authentication system
的laravel 5
應用程序進行操作。用戶可以註冊並登錄。有一項功能可以禁用某些用戶。結果將是禁用用戶將無法登錄,直到他們被啓用。限制某些註冊用戶在Laravel應用程序中登錄
我有一個字段active
在users
表。
我經歷了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();
}
}
共享代碼使用的是驗證用戶身份 –
@GuyS請參閱編輯的問題。 – MASh
請看這裏https://laracasts.com/discuss/channels/laravel/how-to-add-extra-logic-on-login-condition-in-laravel-52 –