同步操作将从 FastAdmin 开源后台框架/FastAdmin 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?phpnamespace app\common\controller;use app\common\library\Auth;use think\Config;use think\Controller;use think\Hook;use think\Lang;use think\Loader;use think\Validate;/*** 前台控制器基类*/class Frontend extends Controller{/*** 布局模板* @var string*/protected $layout = '';/*** 无需登录的方法,同时也就不需要鉴权了* @var array*/protected $noNeedLogin = [];/*** 无需鉴权的方法,但需要登录* @var array*/protected $noNeedRight = [];/*** 权限Auth* @var Auth*/protected $auth = null;public function _initialize(){//移除HTML标签$this->request->filter('trim,strip_tags,htmlspecialchars');$modulename = $this->request->module();$controllername = Loader::parseName($this->request->controller());$actionname = strtolower($this->request->action());// 检测IP是否允许check_ip_allowed();// 如果有使用模板布局if ($this->layout) {$this->view->engine->layout('layout/' . $this->layout);}$this->auth = Auth::instance();// token$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));$path = str_replace('.', '/', $controllername) . '/' . $actionname;// 设置当前请求的URI$this->auth->setRequestUri($path);// 检测是否需要验证登录if (!$this->auth->match($this->noNeedLogin)) {//初始化$this->auth->init($token);//检测是否登录if (!$this->auth->isLogin()) {$this->error(__('Please login first'), 'index/user/login');}// 判断是否需要验证权限if (!$this->auth->match($this->noNeedRight)) {// 判断控制器和方法判断是否有对应权限if (!$this->auth->check($path)) {$this->error(__('You have no permission'));}}} else {// 如果有传递token才验证是否登录状态if ($token) {$this->auth->init($token);}}$this->view->assign('user', $this->auth->getUser());// 语言检测$lang = $this->request->langset();$lang = preg_match("/^([a-zA-Z\-_]{2,10})\$/i", $lang) ? $lang : 'zh-cn';$site = Config::get("site");$upload = \app\common\model\Config::upload();// 上传信息配置后Hook::listen("upload_config_init", $upload);// 配置信息$config = ['site' => array_intersect_key($site, array_flip(['name', 'cdnurl', 'version', 'timezone', 'languages'])),'upload' => $upload,'modulename' => $modulename,'controllername' => $controllername,'actionname' => $actionname,'jsname' => 'frontend/' . str_replace('.', '/', $controllername),'moduleurl' => rtrim(url("/{$modulename}", '', false), '/'),'language' => $lang];$config = array_merge($config, Config::get("view_replace_str"));Config::set('upload', array_merge(Config::get('upload'), $upload));// 配置信息后Hook::listen("config_init", $config);// 加载当前控制器语言包$this->loadlang($controllername);$this->assign('site', $site);$this->assign('config', $config);}/*** 加载语言文件* @param string $name*/protected function loadlang($name){$name = Loader::parseName($name);$name = preg_match("/^([a-zA-Z0-9_\.\/]+)\$/i", $name) ? $name : 'index';$lang = $this->request->langset();$lang = preg_match("/^([a-zA-Z\-_]{2,10})\$/i", $lang) ? $lang : 'zh-cn';Lang::load(APP_PATH . $this->request->module() . '/lang/' . $lang . '/' . str_replace('.', '/', $name) . '.php');}/*** 渲染配置信息* @param mixed $name 键名或数组* @param mixed $value 值*/protected function assignconfig($name, $value = ''){$this->view->config = array_merge($this->view->config ? $this->view->config : [], is_array($name) ? $name : [$name => $value]);}/*** 刷新Token*/protected function token(){$token = $this->request->param('__token__');//验证Tokenif (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {$this->error(__('Token verification error'), '', ['__token__' => $this->request->token()]);}//刷新Token$this->request->token();}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。