|
|
 目录:/vendor/karsonzhang/fastadmin-addons/src/addons/Controller.php
- protected function _initialize()
- {
- // 检测IP是否允许
- if (function_exists("check_ip_allowed")) {
- check_ip_allowed();
- }
- // 渲染配置到视图中
- $config = get_addon_config($this->addon);
- $this->view->assign("config", $config);
- $lang = $this->request->langset();
- $lang = preg_match("/^([a-zA-Z\-_]{2,10})\$/i", $lang) ? $lang : 'zh-cn';
- // 加载系统语言包
- Lang::load([
- ADDON_PATH . $this->addon . DS . 'lang' . DS . $lang . EXT,
- ]);
- // 设置替换字符串
- $cdnurl = Config::get('site.cdnurl');
- $this->view->replace('__ADDON__', $cdnurl . "/assets/addons/" . $this->addon);
- $this->auth = Auth::instance();
- // token
- $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
- $path = 'addons/' . $this->addon . '/' . str_replace('.', '/', $this->controller) . '/' . $this->action;
- // 设置当前请求的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);
- }
- }
- // 如果有使用模板布局
- if ($this->layout) {
- $this->view->engine->layout('layout/' . $this->layout);
- }
- $this->view->assign('user', $this->auth->getUser());
- $site = Config::get("site");
- $upload = \app\common\model\Config::upload();
- // 上传信息配置后
- Hook::listen("upload_config_init", $upload);
- Config::set('upload', array_merge(Config::get('upload'), $upload));
- // 加载当前控制器语言包
- $this->assign('site', $site);
- }
复制代码
|
|