feat: 将用户登录信息与普通缓存数据区分存储

This commit is contained in:
augushong
2025-04-22 09:03:51 +08:00
parent c1042ce1c6
commit a078c14af7
3 changed files with 16 additions and 9 deletions

View File

@@ -1,4 +1,6 @@
<?php
use think\facade\App;
use think\facade\Env;
// +----------------------------------------------------------------------
@@ -25,6 +27,11 @@ return [
// 序列化机制 例如 ['serialize', 'unserialize']
'serialize' => [],
],
'login' => [
'type' => 'File',
// 缓存保存目录
'path' => App::getRuntimePath() . 'login/',
],
// 更多的缓存连接
],
];

View File

@@ -82,7 +82,7 @@ class LoginBase extends AdminController
$admin['expire_time'] = $post['keep_login'] == 1 ? true : time() + 7200;
session('admin', $admin);
$token = md5(uniqid());
Cache::set($token, $admin, $post['keep_login'] == 1 ? time() + 86400 * 7 : time() + 7200);
Cache::store('login')->set($token, $admin, $post['keep_login'] == 1 ? time() + 86400 * 7 : time() + 7200);
Session::delete('back-url');
$this->success('登录成功', ['token' => $token], $back_url);
@@ -102,7 +102,7 @@ class LoginBase extends AdminController
session('admin', null);
$token = $this->readHeaderToken();
if ($token) {
Cache::delete($token);
Cache::store('login')->delete($token);
}
$this->success('退出登录成功');
}

View File

@@ -188,7 +188,7 @@ function get_session_admin($key = null)
{
$token = read_header_token();
if (!empty($token)) {
$admin = Cache::get($token);
$admin = Cache::store('login')->get($token);
} else {
$admin = session('admin');
}