From 2c87d4a701e13280d506f6f5e1cd154f390967cf Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 13 Sep 2022 19:24:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E8=A2=AB=20ban=20?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Middleware/Authenticate.php | 8 +++++++- app/Models/User.php | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 6c2dae3..d270c8c 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -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); } } diff --git a/app/Models/User.php b/app/Models/User.php index 8b2ef6a..ced9315 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -41,6 +41,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac protected $casts = [ 'email_verified_at' => 'datetime', 'balance' => 'float', + 'banned_at' => 'datetime', ];