CodeIgniter Forums
Help choosing auth plugin - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help choosing auth plugin (/showthread.php?tid=27584)



Help choosing auth plugin - El Forum - 02-15-2010

[eluser]NachoF[/eluser]
Im gonna be building an app in codeigniter soon.. Ill be using Datamapper (if it makes a difference).

My app requires two kinds of roles. admins and users.. no one can register, only admins can create users or other admins (and many other actions that users cant do, of course). Thats it... which auth plugins is most appropriate?... My main concern is that most auth plugins come with the ability for people to register to a site buti dont want that... Only admins well be creating users and other admins.
thanks in advance


Help choosing auth plugin - El Forum - 02-15-2010

[eluser]laytone[/eluser]
Its easiest just to write your own Auth. Look into extending your controllers with MY_Controller and implement a '_checkLogin()' function.

When you controllers extend MY_Controller(), start with the constructor and call $this->_checkLogin()

This is how the Constructors in my 'Protected' controllers look:

Code:
class Admin extends MY_Controller {
    
    public function __construct(){
        parent::__construct ();
        $this->load->model('Admin_model');
                //The next line of code makes sure I'm not trying to login and if I am not, it checks the login for usertype 'admin'
        if ($this->uri->segment(2) != 'login') $this->_check_login('admin');
        //$this->output->enable_profiler(TRUE);
    }

}

Here is an example of my /application/libraries/MY_Controller.php
Code:
class MY_Controller extends Controller {
    public function __construct() {
        parent::Controller ();
    }

    function _check_login($forwhat = 'controlpanel'){
        if ($this->session->userdata('loggedin') != TRUE){
            redirect ($forwhat.'/login');
        } else {
            if ($this->session->userdata('usertype') != $forwhat){
                $this->session->sess_destroy();
                redirect ($forwhat.'/login');
            }
        }
    }
}
This particular application has 3 types of users, controlpanel = end user, admin = the admins, and salesfloor = telemarketer login.

My controllers are the named after the user types so its easy to send the person to the correct login page (admin/login, controlpanel/login, salesfloor/login)

Its easy.