Skip to content

Commit 569078c

Browse files
committed
新增通用Token验证方法
1 parent 12b420a commit 569078c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"homepage": "https://github.com/karsonzhang/fastadmin-addons",
55
"license": "Apache-2.0",
66
"minimum-stability": "dev",
7-
"version": "1.2.2",
7+
"version": "1.2.3",
88
"authors": [
99
{
1010
"name": "Karson",

src/addons/Controller.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use think\Lang;
99
use think\Loader;
1010
use think\Request;
11+
use think\Validate;
1112

1213
/**
1314
* 插件基类控制器
@@ -198,4 +199,20 @@ protected function fetch($template = '', $vars = [], $replace = [], $config = []
198199
return parent::fetch($template, $vars, $replace, $config);
199200
}
200201

202+
/**
203+
* 刷新Token
204+
*/
205+
protected function token()
206+
{
207+
$token = $this->request->param('__token__');
208+
209+
//验证Token
210+
if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {
211+
$this->error(__('Token verification error'), '', ['__token__' => $this->request->token()]);
212+
}
213+
214+
//刷新Token
215+
$this->request->token();
216+
}
217+
201218
}

0 commit comments

Comments
 (0)