Provides various official and user-released code examples and code reference. You are welcome to exchange and learn the ultra-simple RBAC implementation.
Transform the official RBAC and provide powerful role permissions.
/**
+ ----------------------------------------------------------
* Obtain the list of all permissions for the current authentication number.
+ ----------------------------------------------------------
* @ Param integer $ authId user ID
+ ----------------------------------------------------------
* @ Access public
+ ----------------------------------------------------------
*/
Static public function getAccessList ($ authId)
{
// Echo"
"; Print_r ($ authId); exit;
// Database-based permission data
$ 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 );
// Read project module Permissions
If ($ app ['auth _ type'] = 0) // node authorization
{
$ 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) // module authorization
{
$ Access [$ o_module_name] [strtoupper ($ auth_type [$ app ['auth _ type'])] = true;
}
If ($ app ['auth _ type'] = 2) // operation authorization
{
$ Access [strtoupper ($ auth_type [$ app ['auth _ type'])] [$ o_action_name] = true;
}
}
// Modules that do not require authentication
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 download: 75 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB