原生php写rbac,超简单的RBAC实现

超简单的RBAC实现

将官方的RBAC进行改造,也现实强大的角色权限/**

+----------------------------------------------------------

* 取得当前认证号的所有权限列表

+----------------------------------------------------------

* @param integer $authId 用户ID

+----------------------------------------------------------

* @access public

+----------------------------------------------------------

*/

static public function getAccessList($authId)

{

//echo "";print_r($authId);exit;

// Db方式权限数据

$db = Db::getInstance(C('RBAC_DB_DSN'));

$auth_type = C("AUTH_TYPE");

$table = array('role'=>C("DB_PREFIX").C('RBAC_ROLE_TABLE'),'user'=>C("DB_PREFIX").C('RBAC_USER_TABLE'),'access'=>C("DB_PREFIX").C('RBAC_ACCESS_TABLE'),'node'=>C("DB_PREFIX").C('RBAC_NODE_TABLE'));

$sql = "select node.auth_type,node.id,node.action,node.action_name,node.module,node.module_name from ".

$table['role']." as role,".

$table['user']." as user,".

$table['access']." as access ,".

$table['node']." as node ".

"where user.u_id='{$authId}' and user.role_id=role.id and access.role_id=role.id and role.status=1 and access.node_id=node.id and node.status=1";

$apps = $db->query($sql);

require_once('./Conf/Admin/authoritys.php');

$access = array();

foreach($apps as $key=>$app)

{

$appId = $app['id'];

$module_name = $app['module'];

$action_name = $app['action'];

$o_module_name = strtoupper($module_name);

$o_action_name = strtoupper($action_name);

$l_module_name = strtolower($module_name);

$l_action_name = strtolower($action_name);

// 读取项目的模块权限

if($app['auth_type']==0) //节点授权

{

$access[$o_module_name][$o_action_name] = true;

if(isset($authoritys['all'][$l_action_name]))

{

$authoritys_list = $authoritys['all'][$l_action_name];

foreach($authoritys_list as $authority_item)

{

$access[$o_module_name][strtoupper($authority_item)] = true;

}

}

if(isset($authoritys['actions'][$l_module_name][$l_action_name]))

{

$authoritys_list = $authoritys['actions'][$l_module_name][$l_action_name];

foreach($authoritys_list as $authority_item)

{

$access[$o_module_name][strtoupper($authority_item)] = true;

}

}

}

if($app['auth_type']==1) //模块授权

{

$access[$o_module_name][strtoupper($auth_type[$app['auth_type']])] = true;

}

if($app['auth_type']==2) //操作授权

{

$access[strtoupper($auth_type[$app['auth_type']])][$o_action_name] = true;

}

}

//不需要认证的模块

if(!empty($authoritys['no']) && is_array($authoritys['no'])){

foreach($authoritys['no'] as $module_name=>$action_name){

$o_module_name = strtoupper($module_name);

$o_action_name = strtoupper(key($action_name));

foreach($action_name as $keymodule=>$valaction){

$keymodule = strtoupper($keymodule);

$access[$o_module_name][$keymodule] = true;

}

}

}

return $access;

}

common.gif

huicms.zip

( 8.45 KB 下载:75 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值