From 334a321bfc0bdfe5225a31b83bb2c9a181d230f5 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Thu, 18 Aug 2022 17:37:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A6=81=E7=94=A8=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=99=BB=E5=BD=95=E6=88=90=E5=8A=9F=20https://guangda?= =?UTF-8?q?git.com/beike/beikeshop/issues/126?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Middleware/ShopAuthenticate.php | 25 +++++++++++++++++++ .../Controllers/Account/LoginController.php | 11 ++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/Http/Middleware/ShopAuthenticate.php b/app/Http/Middleware/ShopAuthenticate.php index 82eb9b3a..ad6b7d2d 100644 --- a/app/Http/Middleware/ShopAuthenticate.php +++ b/app/Http/Middleware/ShopAuthenticate.php @@ -2,12 +2,37 @@ namespace App\Http\Middleware; +use Beike\Models\Customer; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\Middleware\Authenticate as Middleware; class ShopAuthenticate extends Middleware { + /** + * Handle an incoming request. + * + * @param Request $request + * @param \Closure $next + * @param string[] ...$guards + * @return mixed + * + * @throws AuthenticationException + */ + public function handle($request, \Closure $next, ...$guards) + { + $this->authenticate($request, $guards); + + $customer = current_customer(); + if ($customer->status != 1) { + Auth::guard(Customer::AUTH_GUARD)->logout(); + } + + return $next($request); + } + + /** * Get the path the user should be redirected to when they are not authenticated. * diff --git a/beike/Shop/Http/Controllers/Account/LoginController.php b/beike/Shop/Http/Controllers/Account/LoginController.php index 2a42ee4e..e00f65f5 100644 --- a/beike/Shop/Http/Controllers/Account/LoginController.php +++ b/beike/Shop/Http/Controllers/Account/LoginController.php @@ -14,11 +14,7 @@ namespace Beike\Shop\Http\Controllers\Account; use Beike\Models\Customer; use Beike\Shop\Http\Controllers\Controller; use Beike\Shop\Http\Requests\LoginRequest; -use Illuminate\Http\Request; -use function auth; -use function back; -use function redirect; -use function view; +use Illuminate\Support\Facades\Auth; class LoginController extends Controller { @@ -36,6 +32,11 @@ class LoginController extends Controller throw new \Exception("账号密码错误!"); } + $customer = current_customer(); + if ($customer && $customer->status != 1) { + Auth::guard(Customer::AUTH_GUARD)->logout(); + throw new \Exception("用户已被禁用!"); + } return json_success("登录成功!"); } }