I solved this problem using hooks and turned the login process into the controller, thereby having access to user information and setting access levels.
First, I added the following to the hooks.php file in the config folder $hook['post_controller_constructor'][] = array('function' => 'check_login','filename' => 'authority.php','filepath' => 'hooks');
Then I have the following functions in a hook file called authority.php
[EDIT] After reviewing this, I'm going to change it to pre_controller_constructor and see if I can remove what seems like a double flash page on the initial construction. [/ EDIT]
function check_login(){ $CI =& get_instance(); $is_logged_in = $CI->session->userdata('is_logged_in'); if(!$is_logged_in){ $unauth_pages = array(your unauthorized pages go here); if(!in_array($CI->router->class,$unauth_pages)){ $CI->session->set_userdata('before_login_url',current_url()); redirect('login'); } } } function check_authority(){ $CI =& get_instance(); if($CI->session->userdata('usergroupID') == 'SUPADMIN'){return;} $page = $CI->router->class ; $method = $CI->router->method; $method = ($method=='index')?'':$method; $unauth_pages = array(your unauthorized pages go here); if(in_array($page,$unauth_pages))return; $user_group = $CI->session->userdata('usergroupID'); $CI->load->model('user_model'); if($user_group == 'ADMIN' || $user_group == 'USER'){ if($CI->session->userdata('timezone') == ''){ date_default_timezone_set('Canada/Pacific'); } else { date_default_timezone_set($CI->session->userdata('timezone')); } } if( !$CI->user_model->authorized_content($CI->session->userdata('usergroupID'),$page, $method)){ redirect('unauthorized'); } }
With the above, I should not worry about checking on every page, but instead use the ci framework to check for me. If this is not in the unauth array, then this is a page that requires credentials.
Hope this works for you.
source share