常用登陆验证-前端AuthController.php
2022/4/13 11:12:28
本文主要是介绍常用登陆验证-前端AuthController.php,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<?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; } }
这篇关于常用登陆验证-前端AuthController.php的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享
- 2024-11-01开源 PHP 商城项目 CRMEB 安装和使用教程
- 2024-11-01用php和mysql写无限分类,有哪几种方法-icode9专业技术文章分享
- 2024-10-31php数据分表导出时部分数据无法导出什么原因-icode9专业技术文章分享
- 2024-10-30有经验的 PHP 开发者学习一门新的编程语言,有哪些推荐的有前景的语言-icode9专业技术文章分享
- 2024-10-21php 检测图片是否篡改过-icode9专业技术文章分享
- 2024-10-20fruitcake/php-cors 该怎么使用-icode9专业技术文章分享
- 2024-10-18PHP7.1可以使用哪个版本的swoole-icode9专业技术文章分享