igengx
This commit is contained in:
+17
-3
@@ -20,6 +20,7 @@ use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminSession;
|
||||
use app\common\model\auth\SystemRole;
|
||||
use app\common\enum\AdminTerminalEnum;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 管理员token缓存
|
||||
@@ -43,12 +44,15 @@ class AdminTokenCache extends BaseCache
|
||||
//直接从缓存获取
|
||||
$adminInfo = $this->get($this->prefix . $token);
|
||||
if ($adminInfo) {
|
||||
if ((int) ($adminInfo['terminal'] ?? 0) === AdminTerminalEnum::BCR) {
|
||||
$terminal = (int) ($adminInfo['terminal'] ?? 0);
|
||||
if (in_array($terminal, [AdminTerminalEnum::BCR, AdminTerminalEnum::WORKSTATION], true)) {
|
||||
// 长会话每次请求查 DB;即使事务撤销后旧缓存尚未删除,也必须拒绝。
|
||||
$session = AdminSession::where('token', $token)->where('expire_time', '>', time())->find();
|
||||
$admin = $session ? Admin::where('id', $session->admin_id)->where('disable', 0)
|
||||
->field('id,root,work_wechat_userid')->find() : null;
|
||||
if (!$session || (int) $session->terminal !== AdminTerminalEnum::BCR
|
||||
if (!$session || (int) $session->terminal !== $terminal
|
||||
|| ($terminal === AdminTerminalEnum::WORKSTATION && ((int) $session->workstation_slot <= 0
|
||||
|| (int) ($adminInfo['desktop_expires_at'] ?? 0) <= time()))
|
||||
|| (int) $session->admin_id !== (int) $adminInfo['admin_id']
|
||||
|| !$admin) {
|
||||
$this->deleteAdminInfo($token);
|
||||
@@ -93,7 +97,8 @@ class AdminTokenCache extends BaseCache
|
||||
$admin = Admin::where('id', '=', $adminSession->admin_id)
|
||||
->append(['role_id'])
|
||||
->find();
|
||||
if (!$admin || ((int) $adminSession->terminal === AdminTerminalEnum::BCR && (int) $admin->disable !== 0)) {
|
||||
if (!$admin || (in_array((int) $adminSession->terminal, [AdminTerminalEnum::BCR, AdminTerminalEnum::WORKSTATION], true)
|
||||
&& (int) $admin->disable !== 0)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -122,6 +127,15 @@ class AdminTokenCache extends BaseCache
|
||||
'login_ip' => request()->ip(),
|
||||
'work_wechat_userid' => $admin->work_wechat_userid ?? '',
|
||||
];
|
||||
if ((int) $adminSession->terminal === AdminTerminalEnum::WORKSTATION) {
|
||||
$row = Db::name('desktop_login_session')->where('id', $adminSession->workstation_slot)
|
||||
->whereNull('logout_time')->where('due_time', '>', time())->field('expires_at,login_ip')->find();
|
||||
if (!$row) {
|
||||
return [];
|
||||
}
|
||||
$adminInfo['desktop_expires_at'] = (int) $row['expires_at'];
|
||||
$adminInfo['login_ip'] = $row['login_ip'];
|
||||
}
|
||||
$this->set($this->prefix . $token, $adminInfo, new \DateTime(Date('Y-m-d H:i:s', $adminSession->expire_time)));
|
||||
return $adminInfo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user