Skip to content

Commit

Permalink
Updated to support CI-3
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisaha committed Mar 13, 2016
1 parent 1a9343f commit 0d68daf
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 42 deletions.
16 changes: 6 additions & 10 deletions ezRbacHook.php → EzRbacHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class EzRbacHook
function __construct()
{
//Get the Codeigniter instance
$this->CI = & get_instance();
$this->CI = get_instance();

//Load al required core library
$this->load_libraries();
Expand All @@ -63,7 +63,6 @@ function __construct()
//Load configurations
$this->loadConfiguration();


//Get list of public controller from the config file
$this->_public_controller = $this->CI->config->item('public_controller', 'ez_rbac') ?
$this->CI->config->item('public_controller', 'ez_rbac') :
Expand All @@ -85,13 +84,9 @@ function __construct()
private function loadConfiguration()
{
$library_directory = basename($this->CI->ezRbacPath);

//We should use our package resource!
$this->CI->load->add_package_path(APPPATH . "third_party/$library_directory/");
$this->CI->load->remove_package_path(APPPATH);
$this->CI->config->load('ez_rbac', TRUE, TRUE);
$this->CI->load->remove_package_path(APPPATH . "third_party/$library_directory/");
$this->CI->config->load('ez_rbac', TRUE, TRUE);
$this->CI->load->add_package_path(APPPATH . "third_party/$library_directory/");
}

/**
Expand Down Expand Up @@ -173,9 +168,8 @@ function accessCheck()
}


$controller_methods = get_class_methods($this->_controller_name);
$controller_methods = get_class_methods(ucfirst($this->_controller_name));
$method=$this->CI->router->fetch_method();

//Called method does not exist!
if(!in_array($method, $controller_methods)){
return null;
Expand All @@ -192,7 +186,9 @@ function accessCheck()
$this->_isAjaxCall = ($this->CI->input->get('ajax') || $this->CI->input->is_ajax_request());

$access_map = $this->CI->accessmap->get_access_map();

if (!in_array($method, $access_map)) { //The method is not in default acess map

if (!isset($this->_custom_access_map[$method])) { //The method is not defined in custom access map
if ($this->CI->config->item('default_access', 'ez_rbac')) {
return TRUE; //Default access for action is set to true
Expand Down Expand Up @@ -233,7 +229,7 @@ private function load_libraries()
{
$this->CI->load->helper(array('cookie', 'url', 'file'));
$this->CI->load->database();
$this->CI->load->library(array('session', 'sha1', 'encrypt', 'form_validation'));
$this->CI->load->library(array('session', 'encrypt', 'form_validation'));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Key Features

Current Stable Release
======================
[v1.2.2 Released](https://github.com/xiidea/ezRbac/archive/v1.2.2.zip)!
[v1.3.0 Released](https://github.com/xiidea/ezRbac/archive/v1.3.0.zip)!


How To Install
Expand Down Expand Up @@ -274,4 +274,5 @@ enable clean url for management interface by adding routing rule. if <code>$conf

Dependencies
============
To use this library you need **Codeigniter 2.1**
To use this library you need **Codeigniter 3.0+**
For older version use 2.x branch
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"extra": {
"installer-name": "ezRbac",
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.3.x-dev"
}
}
}
7 changes: 4 additions & 3 deletions libraries/accessmap.php → libraries/Accessmap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* AccessMap class file.
* Accessmap class file.
* A Simple Access Control Mapping Library
*
* @version 1.0
Expand All @@ -11,7 +11,7 @@
* @copyright Copyright &copy; 2012 Roni Saha
* @license GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
*/
class AccessMap{
class Accessmap{

private

Expand Down Expand Up @@ -57,7 +57,7 @@ class AccessMap{
*/
function __construct($param = array())
{
$this->CI = & get_instance();
$this->CI = get_instance();

$controller = (isset($param["controller"])) ? strtolower($param["controller"]) : FALSE;
$this->_login_session_key = $this->CI->config->item('login_session_key', 'ez_rbac');
Expand Down Expand Up @@ -94,6 +94,7 @@ public function initialize($controller, $access_role = FALSE)
{

$this->_access_val = $this->get_permission($controller, $access_role);

$this->_access_map_array_size = count($this->_access_arr);
}

Expand Down
16 changes: 8 additions & 8 deletions libraries/ezlogin.php → libraries/Ezlogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
*
*/
class ezlogin
class Ezlogin
{
/**
* @var CI_Controller CI instance reference holder
Expand All @@ -32,7 +32,7 @@ class ezlogin
*/
function __construct()
{
$this->CI = & get_instance();
$this->CI = get_instance();
$this->_login_session_key = $this->CI->config->item('login_session_key', 'ez_rbac');
$this->_user_schema = $this->CI->config->item('schema_user_table', 'ez_rbac');
}
Expand All @@ -50,31 +50,31 @@ private function validation_rule($index = 0)
array(
'field' => 'username',
'label' => 'Email',
'rules' => 'trim|required|valid_email|xss_clean'
'rules' => 'trim|required|valid_email'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required|xss_clean|min_length[' . $this->CI->config->item('password_min_length', 'ez_rbac') . ']'
'rules' => 'trim|required|min_length[' . $this->CI->config->item('password_min_length', 'ez_rbac') . ']'
)
),
array(
array(
'field' => 'username',
'label' => 'Email',
'rules' => 'trim|required|valid_email|xss_clean'
'rules' => 'trim|required|valid_email'
)
),
array(
array(
'field' => 'password',
'label' => 'New Password',
'rules' => 'trim|required|xss_clean|min_length[' . $this->CI->config->item('password_min_length', 'ez_rbac') . ']|matches[re_password]'
'rules' => 'trim|required|min_length[' . $this->CI->config->item('password_min_length', 'ez_rbac') . ']|matches[re_password]'
),
array(
'field' => 're_password',
'label' => 'Re-Type Password',
'rules' => 'trim|required|xss_clean|min_length[' . $this->CI->config->item('password_min_length', 'ez_rbac') . ']'
'rules' => 'trim|required|min_length[' . $this->CI->config->item('password_min_length', 'ez_rbac') . ']'
)
),
);
Expand Down Expand Up @@ -181,7 +181,7 @@ private function process_login()
if (!is_null($user = $this->CI->ezuser->get_user_by_email($useemail))) { //email ok

// Does password match hash in database?
if ($this->CI->encrypt->sha1($password . $user->{$this->_user_schema['salt']}) === $user->{$this->_user_schema['password']}) { // password ok
if (sha1($password . $user->{$this->_user_schema['salt']}) === $user->{$this->_user_schema['password']}) { // password ok
return $this->register_session($user, $remember);
}
// fail - wrong password
Expand Down
6 changes: 3 additions & 3 deletions libraries/ezmanage.php → libraries/Ezmanage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
*
*/
class ezmanage
class Ezmanage
{
/**
* @var CI_Controller CI instance reference holder
Expand All @@ -34,7 +34,7 @@ class ezmanage
*/
function __construct($param)
{
$this->CI = & get_instance();
$this->CI = get_instance();
if(empty($param)){
$this->login();
return;
Expand All @@ -55,7 +55,7 @@ private function login(){
redirect($this->uri('acl'));
}

$this->CI->form_validation->set_rules('password', 'Password', 'required|xss');
$this->CI->form_validation->set_rules('password', 'Password', 'required');
if ($this->CI->form_validation->run() == FALSE){
$data['form_error'] = validation_errors();
$this->CI->load->view('manage/login', $data);
Expand Down
4 changes: 2 additions & 2 deletions libraries/ezmedia.php → libraries/Ezmedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
*
*/

class ezmedia
class Ezmedia
{
private $_usecache = TRUE;

private $CI;

function __construct()
{
$this->CI = & get_instance();
$this->CI = get_instance();

$file = $this->CI->ezRbacPath . DIRECTORY_SEPARATOR . $this->CI->ezuri->ruri_string(DIRECTORY_SEPARATOR);

Expand Down
4 changes: 2 additions & 2 deletions libraries/ezrbac.php → libraries/Ezrbac.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

class ezrbac
class Ezrbac
{

/**
Expand All @@ -30,7 +30,7 @@ class ezrbac
*/
public function __construct()
{
$this->CI = & get_instance();
$this->CI = get_instance();
$this->CI->load->model('ezuser');
$this->CI->load->library('ezlogin');
$this->CI->load->model('manage/user_role');
Expand Down
4 changes: 2 additions & 2 deletions libraries/ezuri.php → libraries/Ezuri.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
*
*/
class ezuri
class Ezuri
{
/**
* @var CI_Controller CI instance reference holder
Expand Down Expand Up @@ -44,7 +44,7 @@ class ezuri
*/
function __construct()
{
$this->CI = & get_instance();
$this->CI = get_instance();
$this->_manage_url = $this->CI->config->item('ezrbac_url', 'ez_rbac');
$this->_use_routing = $this->CI->config->item('use_routing', 'ez_rbac');
$this->_base_url = $this->_use_routing ? $this->_manage_url : $this->CI->router->default_controller . "/index/$this->_manage_url";
Expand Down
2 changes: 1 addition & 1 deletion models/ezuser.php → models/Ezuser.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function __construct()
{
// Call the Model constructor
parent::__construct();
$this->CI=& get_instance();
$this->CI= get_instance();

$this->_table_name=$this->CI->config->item('user_table','ez_rbac');
$this->_meta_table=$this->CI->config->item('user_meta_table','ez_rbac');
Expand Down
4 changes: 2 additions & 2 deletions models/user_access_map.php → models/User_access_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
*
*/
class user_access_map extends CI_Model {
class User_access_map extends CI_Model {
/**
* @var CI_Controller CI instance reference holder
*/
Expand All @@ -38,7 +38,7 @@ function __construct()
{
// Call the Model constructor
parent::__construct();
$this->CI=& get_instance();
$this->CI= get_instance();

$this->_table_name=$this->CI->config->item('access_map_table','ez_rbac');
$this->_user_role_table=$this->CI->config->item('user_role_table','ez_rbac');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
*
*/
class ezcontrollers extends CI_Model {
class Ezcontrollers extends CI_Model {
/**
* @var CI_Controller CI instance reference holder
*/
Expand All @@ -33,7 +33,7 @@ function __construct()
{
// Call the Model constructor
parent::__construct();
$this->CI=& get_instance();
$this->CI= get_instance();
$this->_controllers_basepath=realpath(APPPATH.DIRECTORY_SEPARATOR."controllers");
}

Expand Down
4 changes: 2 additions & 2 deletions models/manage/user_role.php → models/manage/User_role.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
*
*/
class user_role extends CI_Model {
class User_role extends CI_Model {
/**
* @var CI_Controller CI instance reference holder
*/
Expand All @@ -41,7 +41,7 @@ function __construct()
{
// Call the Model constructor
parent::__construct();
$this->CI = & get_instance();
$this->CI = get_instance();
$this->_table_name=$this->CI->config->item('user_role_table','ez_rbac');
$schema=$this->CI->config->item('schema_user_role','ez_rbac');
($schema) AND $this->_schema=$schema;
Expand Down
4 changes: 2 additions & 2 deletions models/user_autologin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
*
*/
class User_Autologin extends CI_Model
class User_autologin extends CI_Model
{
/**
* @var $_table_name store auto_login_table name
Expand All @@ -34,7 +34,7 @@ class User_Autologin extends CI_Model
function __construct()
{
parent::__construct();
$CI=& get_instance();
$CI= get_instance();
$this->_table_name=$CI->config->item('auto_login_table','ez_rbac');
$this->_user_table_name=$CI->config->item('user_table','ez_rbac');
$this->_user_schema=$CI->config->item('schema_user_table','ez_rbac');
Expand Down

0 comments on commit 0d68daf

Please sign in to comment.