一、修改vendor/encore/laravel-admin/src/Controllers/AuthController.php中postLogin方法
if ($this->guard()->attempt($credentials, $remember)) {
$res = $this->sendLoginResponse($request);
//登录成功 记录token
$this->sendCookieToken($this->guard()->user(), $request);
$this->clearLoginAttempts($request);
return $res;
}
添加方法sendCookieToken
/*
* 制作token,用于单用户登录验证
*/
public function sendCookieToken($member, Request $request) {
$time = time();
$sinleToken = md5($request->getClientIp().$member->id.$time);
Cache::put($member->id, $time, 300);
\Cache::put('check_code'.$member->id, null, 300);
$request->session()->put('SINGLETOKEN', $sinleToken);
}
二、使用中间件验证是否重复登录
1、admin.php 中 route数组 middleware 添加中间件single_m