From a078c14af7c71a1b31465966745fb54113e7d500 Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 22 Apr 2025 09:03:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=86=E7=94=A8=E6=88=B7=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=BF=A1=E6=81=AF=E4=B8=8E=E6=99=AE=E9=80=9A=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=95=B0=E6=8D=AE=E5=8C=BA=E5=88=86=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/cache.php | 19 +++++++++++++------ extend/base/admin/controller/LoginBase.php | 4 ++-- extend/base/helper.php | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/config/cache.php b/config/cache.php index dd492df..ebbb2ff 100644 --- a/config/cache.php +++ b/config/cache.php @@ -1,4 +1,6 @@ Env::get('cache.driver', 'file'), // 缓存连接方式配置 - 'stores' => [ + 'stores' => [ 'file' => [ // 驱动方式 - 'type' => 'File', + 'type' => 'File', // 缓存保存目录 - 'path' => '', + 'path' => '', // 缓存前缀 - 'prefix' => '', + 'prefix' => '', // 缓存有效期 0表示永久缓存 - 'expire' => 0, + 'expire' => 0, // 缓存标签前缀 'tag_prefix' => 'tag:', // 序列化机制 例如 ['serialize', 'unserialize'] - 'serialize' => [], + 'serialize' => [], + ], + 'login' => [ + 'type' => 'File', + // 缓存保存目录 + 'path' => App::getRuntimePath() . 'login/', ], // 更多的缓存连接 ], diff --git a/extend/base/admin/controller/LoginBase.php b/extend/base/admin/controller/LoginBase.php index f405a07..830ebbf 100644 --- a/extend/base/admin/controller/LoginBase.php +++ b/extend/base/admin/controller/LoginBase.php @@ -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('退出登录成功'); } diff --git a/extend/base/helper.php b/extend/base/helper.php index d2f96c1..794999c 100644 --- a/extend/base/helper.php +++ b/extend/base/helper.php @@ -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'); }