nam*_*ess 3 authentication laravel laravel-authorization laravel-5.3
我有一个问题,我目前正在使用Laravel 5.3开发一个小型站点,并且正在使用它们的基本身份验证供用户注册和登录。
现在,我需要以下内容:每个人都可以注册并登录,但是如果我单击一个按钮(以管理员身份),则可以“阻止”一个特定用户(例如,如果他不允许这样做),我不会完全删除数据库中的行,但是以某种方式确保如果用户尝试登录,则会收到一条消息,内容为“您无法再登录,您的帐户已被阻止,请联系管理员以获取更多信息”或类似内容。问题是:什么是最好的方法?我没有找到内置的内容,如果我错了,请纠正我...当然,我可以更改users表并添加一个名为“ blocked”的列,通常设置为false,然后使用按钮将其设置为如果是true,则在登录时以某种方式检查此值,并显示此消息(如果为true),并且不允许登录。这是最好的方法吗?如果是,我将在哪里检查该值,然后如何显示该消息?如果没有,还有什么更好的方法?
我会按照您的建议进行操作-使用blocked或active列来指示用户是否应该能够登录。过去我做过类似的事情时,要在登录时检查此值,我将退出框登录功能进入我的LoginController并添加了一点。我的登录方法现在如下所示:
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function login(Request $request)
{
$this->validateLogin($request);
$user = User::where('email', $request->email)->firstOrFail();
if ( $user && !$user->active ) {
return $this->sendLockedAccountResponse($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);
}
Run Code Online (Sandbox Code Playgroud)
我还添加了以下功能来处理不活跃的用户:
/**
* Get the locked account response instance.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function sendLockedAccountResponse(Request $request)
{
return redirect()->back()
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginUsername() => $this->getLockedAccountMessage(),
]);
}
/**
* Get the locked account message.
*
* @return string
*/
protected function getLockedAccountMessage()
{
return Lang::has('auth.locked')
? Lang::get('auth.locked')
: 'Your account is inactive. Please contact the Support Desk for help.';
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5236 次 |
| 最近记录: |