Yup, it makes it really easy to change permissions in the database, plus its really fast since it only does 1 query.
I finished making the code, here it is:
function check()
{
$_pass = false;
$_group = $this->obj->session->userdata('group_id');
if ( $this->obj->session AND $this->obj->config->item('CL_Auth') AND !empty($_group) )
{
$_controller = '/'.$this->obj->uri->rsegment(1);
$_action = $_controller.'/'.$this->obj->uri->rsegment(2);
$query = $this->obj->group_uri->findURI(array($_controller, $_action), $_group);
if ( $query->num_rows() )
{
$data = $query->row();
$_pass = true;
$this->_fullAccess = $data->is_admin;
}
else
{
$query = $this->obj->group_uri->globalAccess($_group);
if ( $query->num_rows() )
{
$data = $query->row();
$_pass = true;
$this->_fullAccess = $data->is_admin;
}
}
}
if ( $_pass == false )
{
$this->denyAccess($_group);
}
}
function isAdmin()
{
return $this->_fullAccess;
}
So all you do is call “$this->auth->check()” at the top of the controller if you want to protect it all, or sit it within an action.
Heres the model as well:
function findURI($_uri=array(), $_group_id)
{
$this->db->where_in('request_uri', $_uri);
$this->db->where('group_id', $_group_id);
return $this->db->get($this->_table);
}
function globalAccess($_group_id)
{
$this->db->where(array('group_id' => $_group_id, 'request_uri' => '/'));
return $this->db->get($this->_table);
}
Some example data too:
group_id | request_uri | is_admin
1 | / | 1
2 | /home | 1
3 | /home/test | 0