-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Automated Login Controller
pushpinderbagga edited this page Jan 8, 2013
·
4 revisions
I just wanted to contribute/discuss as to how we can control access to a particular section in our web application.
Lets suppose we have a Controller called "Dashboard". We want to restrict only users from the Group "Foxy" to view it. Instead of extending the Dashboard controller with CI_Controller, I would extent it by Foxy_Controller which is a Library file as follows.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Foxy_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
if (! $this->ion_auth->logged_in())
{
redirect('login', 'refresh');
}else{
if(! $this->ion_auth->in_group('Foxy')){
//Someone is playing here - lets logout to be safe
$logout = $this->ion_auth->logout();
redirect('login', 'refresh');
//You can instead show a 404 Error page here. Your call!
}
}
}
}So now whenever I need a "Foxy" only section - I would just extend the controller by Foxy_Controller. Suggestions are most welcome!