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("登录成功!"); } }