rbac权限管理方法

10 篇文章 0 订阅

权限管理

并不是类,只是自己瞎琢磨出来的方法,放在common里面的,反正emmmm….能用就行这里写图片描述
use think\Request;
use think\Controller;
use think\Session;
use app\admin\model\RbacUser;
use app\admin\model\RbacRole;
use app\admin\model\RbacAccess;
use app\admin\model\RbacRoleAccess;
use app\admin\model\RbacUserRole;


function getRolePrivilege(){
    $rbac_user = new RbacUser();
    $rbac_access = new RbacAccess();
    $rbac_role_access = new RbacRoleAccess();
    $rbac_role = new RbacRole();
    $rbac_user_role = new RbacUserRole();

    $id = Session::get('u_id');
    $role_user = $rbac_user_role->selUserRole($id);
    $r_id = $role_user['r_id'];
    $access = $rbac_role_access->selRoleAccess($r_id);
    $access_url = explode(';', $access['a_id']);
    $urls = $rbac_access->selAccessUrl($access_url);

    if (!empty($urls)) {
        foreach ($urls as $key => $value) {
            if ((strpos($value['urls'], ';')) !== false) {
                $merge[$key] = explode(';', $value['urls']);
            } else {
                $url[$key] = $value['urls'];
            }
        }
        $pathData = $_SERVER['REQUEST_URI'];
        $data = parse_url($pathData);
        $path = $data['path'];
        $p = '/';
        $pos = newstripos($path, $p, 4);
        if ($pos) {
            $path = str_replace(substr($path, $pos), '', $path) ;
        }
        if (!empty($url)) {
            array_unshift($merge,$url);
            foreach ($merge as $key => $value) {
                foreach ($value as $key1 => $value1) {
                    $url_value[]=  $value1;
                }

            }
            if (!in_array($path, $url_value)) {
                header("Location:/admin/index/error_page");
                 die;
            }
        } else {
            foreach ($merge as $key => $value) {
                foreach ($value as $key1 => $value1) {
                    $url_value[]=  $value1;
                }
            }
            if (!in_array($path, $url_value)) {
                header("Location:/admin/index/error_page");
                 die;
            }
        }
    }
}
function newstripos($str, $find, $count, $offset=0)
{
    $pos = stripos($str, $find, $offset);
    $count--;
    if ($count > 0 && $pos !== FALSE)
    {
        $pos = newstripos($str, $find ,$count, $pos+1);
    }
    return $pos;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值