controller->csrf_state = true; if ($this->app->request->isPost() && !TokenService::instance()->checkFormToken()) { if ($return) return false; $this->controller->error($this->controller->csrf_message); } else { return true; } } /** * 清理表单令牌 */ public function clear() { TokenService::instance()->clearFormToken(); } /** * 返回视图内容 * @param string $tpl 模板名称 * @param array $vars 模板变量 * @param string $node CSRF授权节点 */ public function fetchTemplate($tpl = '', $vars = [], $node = null) { throw new HttpResponseException(view($tpl, $vars, 200, function ($html) use ($node) { return preg_replace_callback('/<\/form>/i', function () use ($node) { $csrf = TokenService::instance()->buildFormToken($node); return ""; }, $html); })); } }