超简单的RBAC实现
将官方的RBAC进行改造,也现实强大的角色权限/**<br>
+----------------------------------------------------------<br>
* 取得当前认证号的所有权限列表<br>
+----------------------------------------------------------<br>
* @param integer $authId 用户ID<br>
+----------------------------------------------------------<br>
* @access public<br>
+----------------------------------------------------------<br>
*/<br>
static public function getAccessList($authId)<br>
{<br>
//echo "<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">";print_r($authId);exit;<br>
// Db方式权限数据<br>
$db = Db::getInstance(C('RBAC_DB_DSN'));<br>
$auth_type = C("AUTH_TYPE");<br>
$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'));<br>
$sql = "select node.auth_type,node.id,node.action,node.action_name,node.module,node.module_name from ".<br>
$table['role']." as role,".<br>
$table['user']." as user,".<br>
$table['access']." as access ,".<br>
$table['node']." as node ".<br>
"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";<br>
<br>
$apps = $db->query($sql);<br>
require_once('./Conf/Admin/authoritys.php');<br>
$access = array();<br>
foreach($apps as $key=>$app)<br>
{<br>
$appId = $app['id'];<br>
$module_name = $app['module'];<br>
$action_name = $app['action'];<br>
$o_module_name = strtoupper($module_name);<br>
$o_action_name = strtoupper($action_name);<br>
$l_module_name = strtolower($module_name);<br>
$l_action_name = strtolower($action_name);<br>
<br>
// 读取项目的模块权限<br>
if($app['auth_type']==0) //节点授权<br>
{<br>
$access[$o_module_name][$o_action_name] = true;<br>
<br>
if(isset($authoritys['all'][$l_action_name]))<br>
{<br>
$authoritys_list = $authoritys['all'][$l_action_name];<br>
foreach($authoritys_list as $authority_item)<br>
{<br>
$access[$o_module_name][strtoupper($authority_item)] = true;<br>
}<br>
}<br>
<br>
if(isset($authoritys['actions'][$l_module_name][$l_action_name]))<br>
{<br>
$authoritys_list = $authoritys['actions'][$l_module_name][$l_action_name];<br>
foreach($authoritys_list as $authority_item)<br>
{<br>
$access[$o_module_name][strtoupper($authority_item)] = true;<br>
}<br>
}<br>
}<br>
<br>
if($app['auth_type']==1) //模块授权<br>
{<br>
$access[$o_module_name][strtoupper($auth_type[$app['auth_type']])] = true;<br>
}<br>
<br>
if($app['auth_type']==2) //操作授权<br>
{<br>
$access[strtoupper($auth_type[$app['auth_type']])][$o_action_name] = true;<br>
}<br>
}<br>
<br>
//不需要认证的模块<br>
if(!empty($authoritys['no']) && is_array($authoritys['no'])){<br>
foreach($authoritys['no'] as $module_name=>$action_name){<br>
$o_module_name = strtoupper($module_name); <br>
$o_action_name = strtoupper(key($action_name));<br>
foreach($action_name as $keymodule=>$valaction){<br>
$keymodule = strtoupper($keymodule);<br>
$access[$o_module_name][$keymodule] = true;<br>
}<br>
}<br>
<br>
}<br>
return $access;<br>
}</pre><div class="contentsignin">登录后复制</div></div>
huicms.zip ( 8.45 KB 下载:75 次 )
AD:真正免费,域名+虚机+企业邮箱=0元