• 常用登陆验证后端AuthController.php


     1 <?php
     2 
     3 
     4 namespace app\admin;
     5 
     6 use app\model\AdminNode;
     7 use think\facade\View;
     8 
     9 class AuthController extends BaseController
    10 {
    11     // 初始化
    12     public $user;
    13     public $active = 'setting';
    14 
    15     protected function initialize()
    16     {
    17         $this->request->user = session('user');
    18         if (empty($this->request->user)) {
    19             if ($this->request->isAjax()) {
    20                 ErrorException('请登录');
    21             }
    22             cms_redirect(url('/auth/login'));
    23         }
    24 
    25         if (empty($this->request->user['auth_node']['is_admin_role'])) {
    26             cms_redirect(url('/'));
    27         }
    28 
    29         //获取当前访问路由
    30         $url = strtolower('/admin/' . $this->request->controller() . '/' . $this->request->action());
    31 
    32         $auth = $this->request->user['auth_node']['node'];
    33 
    34         //菜单栏
    35         $menu = AdminNode::menu($auth);
    36         $menu = list_to_tree($menu->toArray(), 64, 'pid');
    37         View::assign(['menu' => $menu, 'active' => $this->active, 'user' => $this->request->user]);
    38 
    39         //获取路由映射,权限判断
    40         $route = !empty(config('auth.route')[$url]) ? config('auth.route')[$url] : $url;
    41         if ($route != 'allow_access' && $auth != 'all') {
    42             //获取用户授权路由
    43             $node = AdminNode::node($auth);
    44             if (!in_array($route, $node)) {
    45                 throw new AuthErrorException("未授权访问", 10000, 403);
    46             }
    47         }
    48     }
    49 }
  • 相关阅读:
    R语言中的logical(0)和numeric(0)以及赋值问题
    创建hadoop用户
    虚拟机安装
    spark1-MapReduce
    arcgis1-shp转成mdb
    Actor-配置Maven
    scala6-单词计数(map(),flatMap())
    scala5-数组
    scala4-函数
    scala3-for循环
  • 原文地址:https://www.cnblogs.com/silen0119/p/16139003.html
Copyright © 2020-2023  润新知