This commit is contained in:
Edward Yang 2022-08-18 17:37:01 +08:00
parent 36208c0c35
commit 334a321bfc
2 changed files with 31 additions and 5 deletions

View File

@ -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.
*

View File

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