搜索
系统检测到您的用户名不符合规范:

超简单的RBAC实现

浏览:3638 发布日期:2013年09月24日 分类:功能实现
超简单的RBAC实现
将官方的RBAC进行改造,也现实强大的角色权限/**
+----------------------------------------------------------
* 取得当前认证号的所有权限列表
+----------------------------------------------------------
* @param integer $authId 用户ID
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
static public function getAccessList($authId)
{
//echo "<pre>";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;
}

附件 huicms.zip ( 8.45 KB 下载:85 次 )

收藏
sje410
积分:1721 等级:LV3
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /