<?php
namespace Admin\Controller;
use Think\Controller;
use Org\Util\Rbac;
Class CommonController extends Controller{
Public function _initialize(){
if(!isset($_SESSION[C('USER_AUTH_KEY')])){
$this->redirect('/Admin/Login/index');
}
$notAuth = in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE'))) || in_array(ACTION_NAME, explode(',', C('NOT_AUTH_ACTION')));
if(C('USER_AUTH_ON') && !$notAuth){
RBAC::AccessDecision() || $this->error('没有权限');
}
}
namespace Admin\Controller;
use Think\Controller;
use Org\Util\Rbac;
Class CommonController extends Controller{
Public function _initialize(){
if(!isset($_SESSION[C('USER_AUTH_KEY')])){
$this->redirect('/Admin/Login/index');
}
$notAuth = in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE'))) || in_array(ACTION_NAME, explode(',', C('NOT_AUTH_ACTION')));
if(C('USER_AUTH_ON') && !$notAuth){
RBAC::AccessDecision() || $this->error('没有权限');
}
}
}
3.2.3无需添加GROUP_NAME,,3.2.3取消了用户多入口,用项目分组来替代,无需添加GROUP_NAME
正确写法如上,RBAC::AccessDecision() || $this->error('没有权限');
错误写法:RBAC::AccessDecision(GROUP_NAME) || $this->error('没有权限'); 所有的节点都没有权限

本文介绍了一个基于ThinkPHP框架的后台管理系统中实现权限验证的方法。通过定义CommonController类并覆盖initialize方法,实现用户登录状态检查及未授权访问跳转。同时使用RBAC组件进行细粒度权限判断。
454

被折叠的 条评论
为什么被折叠?



