添加 被 ban 逻辑

This commit is contained in:
iVampireSP.com 2022-09-13 19:24:01 +08:00
parent 14fc6c39c1
commit 2c87d4a701
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 8 additions and 1 deletions

View File

@ -37,10 +37,16 @@ public function __construct(Auth $auth)
*/
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
$auth = $this->auth->guard($guard);
if ($auth->guest()) {
return $this->unauthorized('Unauthorized.');
}
$user = $this->auth->guard($guard)->user();
if ($user->banned_at) {
return $this->forbidden('您已被封禁,原因是: ' . $user->banned_reason);
}
return $next($request);
}
}

View File

@ -41,6 +41,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
protected $casts = [
'email_verified_at' => 'datetime',
'balance' => 'float',
'banned_at' => 'datetime',
];