diff --git a/application/common.php b/application/common.php index d77f951..d772ada 100644 --- a/application/common.php +++ b/application/common.php @@ -48,6 +48,7 @@ function getCurrentMember() function setCurrentMember($data) { + Cache::set('member:info:' . $data['code'], $data); return session('member', $data); } diff --git a/application/common/Model/Member.php b/application/common/Model/Member.php index c66c20b..eae77a1 100644 --- a/application/common/Model/Member.php +++ b/application/common/Model/Member.php @@ -55,7 +55,7 @@ class Member extends CommonModel setCurrentMember($member); !empty($member['authorize']) && NodeService::applyProjectAuthNode(); $member = getCurrentMember(); - $tokenList = JwtService::initToken($member); + $tokenList = JwtService::initToken(['code' => $member['code']]); $accessTokenExp = JwtService::decodeToken($tokenList['accessToken'])->exp; $tokenList['accessTokenExp'] = $accessTokenExp; $loginInfo = ['member' => $member, 'tokenList' => $tokenList, 'organizationList' => $organizationList]; diff --git a/application/project/middleware/Auth.php b/application/project/middleware/Auth.php index 2eb0bf4..cae43d5 100644 --- a/application/project/middleware/Auth.php +++ b/application/project/middleware/Auth.php @@ -9,6 +9,7 @@ use service\NodeService; use think\db\exception\DataNotFoundException; use think\db\exception\ModelNotFoundException; use think\exception\DbException; +use think\facade\Cache; use think\Request; /** @@ -51,10 +52,15 @@ class Auth $msg = ['code' => 401, 'msg' => 'accessToken过期']; return json($msg); } - $msg = ['code' => 401, 'msg' => 'token过期,请重新登录']; + $msg = ['code' => 401, 'msg' => '登录超时,请重新登录']; return json($msg); } - setCurrentMember(get_object_vars($data->data)); + $member = Cache::get('member:info:' . $data->data->code); + if (!$member) { + $msg = ['code' => 401, 'msg' => '登录超时,请重新登录']; + return json($msg); + } + setCurrentMember($member); } // 访问权限检查 if (!empty($access['is_auth']) && !auth($node, 'project')) { diff --git a/config/cache.php b/config/cache.php index b0b9b2b..e24c86a 100644 --- a/config/cache.php +++ b/config/cache.php @@ -24,7 +24,7 @@ 'expire' => 0, ];*/ return [ - 'type' => 'complex', + 'type' => 'redis', // 默认使用的缓存 'default' => [ // 驱动方式