<?PHP namespace app\home; use app\model\AdminNode; use app\model\Cases; use app\model\Illegal; use think\facade\View; use app\model\AdminUser; class AuthController extends BaseController { protected function initialize() { parent::initialize(); $uid = session('uid'); $this->request->user = AdminUser::info(intval($uid)); if (empty($this->request->user)) { if ($this->request->isAjax()) { ErrorException('请登录'); } cms_redirect(url('/auth/login')); } //获取当前访问路由 $url = strtolower('/' . $this->request->controller() . '/' . $this->request->action()); $auth = $this->request->user['auth_node']['node']; //获取路由映射,权限判断 $route = !empty(config('auth.route')[$url]) ? config('auth.route')[$url] : $url; if ($route != 'allow_access' && $auth != 'all') { //获取用户授权路由 $node = AdminNode::node($auth, 'home'); if (!in_array($route, $node)) { throw new NotFoundException("未授权访问", 10000, 403); } } View::assign(['__is_real' => $this->_check_real($url)]); /** * 审批统计 */ $caseexamineCount = Cases::where(function ($query) { if (!in_array('all', $this->request->user['region_id'])) { $query->where([ ['region_id', 'in', $this->request->user['region_id']], ['region_id', '<>', 0], ]); } $query->where('status', Cases::CASE_STATUS_WAIT); })->count(); View::assign(['user' => $this->request->user, 'examine_count' => $caseexamineCount]); } private function _check_real(string $url = '') { if (SystemSetting('user.user_auth') != 1) { return true; } $real_page = '/center/real'; $allow_list = [ $real_page, '/center/setting', '/center/certify', '/center/change', '/file/upload' ]; /** * 有控制台权限的人不需要实名认证 */ if ($this->request->user['disable'] == 1) { return true; } /** * 跳转实名认证页面 */ if (!in_array($url, $allow_list) && $this->request->user['auth'] != 2) { cms_redirect(url($real_page)); } return false; } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。