作者 Karson

新增API基类Token验证

优化后台选项卡判断
... ... @@ -2,9 +2,9 @@
<div class="panel-heading">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs" data-field="{%field%}">
<li class="{:input('get.{%field%}') ? '' : 'active'}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
<li class="{:$Think.get.{%field%} === null ? 'active' : ''}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
{foreach name="{%fieldName%}List" item="vo"}
<li class="{:input('get.{%field%}') == $key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
<li class="{:$Think.get.{%field%} === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div>
... ...
... ... @@ -12,6 +12,7 @@ use think\Loader;
use think\Request;
use think\Response;
use think\Route;
use think\Validate;
/**
* API控制器基类
... ... @@ -304,4 +305,20 @@ class Api
return true;
}
/**
* 刷新Token
*/
protected function token()
{
$token = $this->request->param('__token__');
//验证Token
if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {
$this->error(__('Token verification error'), ['__token__' => $this->request->token()]);
}
//刷新Token
$this->request->token();
}
}
... ...
... ... @@ -531,7 +531,7 @@ class Backend extends Controller
*/
protected function token()
{
$token = $this->request->post('__token__');
$token = $this->request->param('__token__');
//验证Token
if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {
... ...
... ... @@ -142,7 +142,7 @@ class Frontend extends Controller
*/
protected function token()
{
$token = $this->request->post('__token__');
$token = $this->request->param('__token__');
//验证Token
if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {
... ...