优化token生成逻辑

Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
vilson 2019-07-17 15:36:18 +08:00
parent 2dfc891057
commit e7715b3e17
4 changed files with 11 additions and 4 deletions

View File

@ -48,6 +48,7 @@ function getCurrentMember()
function setCurrentMember($data) function setCurrentMember($data)
{ {
Cache::set('member:info:' . $data['code'], $data);
return session('member', $data); return session('member', $data);
} }

View File

@ -55,7 +55,7 @@ class Member extends CommonModel
setCurrentMember($member); setCurrentMember($member);
!empty($member['authorize']) && NodeService::applyProjectAuthNode(); !empty($member['authorize']) && NodeService::applyProjectAuthNode();
$member = getCurrentMember(); $member = getCurrentMember();
$tokenList = JwtService::initToken($member); $tokenList = JwtService::initToken(['code' => $member['code']]);
$accessTokenExp = JwtService::decodeToken($tokenList['accessToken'])->exp; $accessTokenExp = JwtService::decodeToken($tokenList['accessToken'])->exp;
$tokenList['accessTokenExp'] = $accessTokenExp; $tokenList['accessTokenExp'] = $accessTokenExp;
$loginInfo = ['member' => $member, 'tokenList' => $tokenList, 'organizationList' => $organizationList]; $loginInfo = ['member' => $member, 'tokenList' => $tokenList, 'organizationList' => $organizationList];

View File

@ -9,6 +9,7 @@ use service\NodeService;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\exception\DbException; use think\exception\DbException;
use think\facade\Cache;
use think\Request; use think\Request;
/** /**
@ -51,10 +52,15 @@ class Auth
$msg = ['code' => 401, 'msg' => 'accessToken过期']; $msg = ['code' => 401, 'msg' => 'accessToken过期'];
return json($msg); return json($msg);
} }
$msg = ['code' => 401, 'msg' => 'token过期,请重新登录']; $msg = ['code' => 401, 'msg' => '登录超时,请重新登录'];
return json($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')) { if (!empty($access['is_auth']) && !auth($node, 'project')) {

View File

@ -24,7 +24,7 @@
'expire' => 0, 'expire' => 0,
];*/ ];*/
return [ return [
'type' => 'complex', 'type' => 'redis',
// 默认使用的缓存 // 默认使用的缓存
'default' => [ 'default' => [
// 驱动方式 // 驱动方式