From 4359962e1d96f70fe6df06ebba62936c36b4943f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com> Date: Tue, 12 Mar 2024 12:55:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E4=BC=98=E5=8C=96=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8=E5=9F=BA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/Backend.php | 5 ++--- app/common/controller/Frontend.php | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/common/controller/Backend.php b/app/common/controller/Backend.php index ec4a6028..d22dcdb8 100644 --- a/app/common/controller/Backend.php +++ b/app/common/controller/Backend.php @@ -6,7 +6,6 @@ use Throwable; use think\Model; use think\facade\Db; use think\facade\Event; -use think\facade\Cookie; use app\admin\library\Auth; use think\db\exception\PDOException; use think\exception\HttpResponseException; @@ -146,9 +145,8 @@ class Backend extends Api $this->error(mb_convert_encoding($e->getMessage(), 'UTF-8', 'UTF-8,GBK,GB2312,BIG5')); } + $token = get_auth_token(); $this->auth = Auth::instance(); - $routePath = $this->app->request->controllerPath . '/' . $this->request->action(true); - $token = $this->request->server('HTTP_BATOKEN', $this->request->request('batoken', Cookie::get('batoken') ?: false)); if (!action_in_arr($this->noNeedLogin)) { $this->auth->init($token); if (!$this->auth->isLogin()) { @@ -157,6 +155,7 @@ class Backend extends Api ], $this->auth::LOGIN_RESPONSE_CODE); } if (!action_in_arr($this->noNeedPermission)) { + $routePath = ($this->app->request->controllerPath ?? '') . '/' . $this->request->action(true); if (!$this->auth->check($routePath)) { $this->error(__('You have no permission'), [], 401); } diff --git a/app/common/controller/Frontend.php b/app/common/controller/Frontend.php index 3ca45325..b88e0e38 100644 --- a/app/common/controller/Frontend.php +++ b/app/common/controller/Frontend.php @@ -4,7 +4,6 @@ namespace app\common\controller; use Throwable; use think\facade\Event; -use think\facade\Cookie; use app\common\library\Auth; use think\exception\HttpResponseException; @@ -37,9 +36,8 @@ class Frontend extends Api public function initialize(): void { parent::initialize(); + $token = get_auth_token(['ba', 'user', 'token']); $this->auth = Auth::instance(); - $routePath = $this->app->request->controllerPath . '/' . $this->request->action(true); - $token = $this->request->server('HTTP_BA_USER_TOKEN', $this->request->request('ba-user-token', Cookie::get('ba-user-token') ?: false)); if (!action_in_arr($this->noNeedLogin)) { $this->auth->init($token); if (!$this->auth->isLogin()) { @@ -48,6 +46,7 @@ class Frontend extends Api ], $this->auth::LOGIN_RESPONSE_CODE); } if (!action_in_arr($this->noNeedPermission)) { + $routePath = ($this->app->request->controllerPath ?? '') . '/' . $this->request->action(true); if (!$this->auth->check($routePath)) { $this->error(__('You have no permission'), [], 401); }