常用登陆验证-前端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-12-19php8的协程和hyperf的协程有什么区别?-icode9专业技术文章分享
- 2024-12-19php8 的fiber是什么?-icode9专业技术文章分享
- 2024-12-05怎么在php8,1 里面开启 debug?-icode9专业技术文章分享
- 2024-12-05怎么在php8,1 里面开启 debug?-icode9专业技术文章分享
- 2024-11-29使用PHP 将ETH账户的资产汇集到一个账户
- 2024-11-23怎么实现安卓+php 热更新方案?-icode9专业技术文章分享
- 2024-11-22PHP 中怎么实现判断多个值是否为空、null 或者为 false?-icode9专业技术文章分享
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享