Welcome Guest, Not a member yet? Register   Sign In
Best way to handle authentication with MY_Controller ?
#1

[eluser]benoa[/eluser]
I'm currently building a project that requires two layers of authentication : admin and clients.

So I went through many Open Source CI apps in order to see how authentication was managed. Looking at Bamboo Invoice's MY_Controller, I found a smart way to protect a list of controllers :

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends Controller
{

    function My_Controller()
    {
        parent::Controller();

        // a list of unlocked (ie: not password protected) controllers.  We assume
        // controllers are locked if they aren't explicitly on this list
        $unlocked = array('changelog', 'credits', 'donate', 'front', 'help', 'login');

        if ( ! $this->site_sentry->is_logged_in() AND ! in_array(strtolower(get_class($this)), $unlocked))
        {
            redirect('login/');
        }

    }

}

We could store the $unlocked array in a config file, or in a database so that the administrator can decide which parts of the sites are supposed to be restricted access (from the backend). I can see an implementation of roles here too.

I found this was useful, but I would like to know if you ci-mates have another way of managing access to your controllers ?


Messages In This Thread
Best way to handle authentication with MY_Controller ? - by El Forum - 09-18-2009, 11:11 AM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-18-2009, 06:40 PM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 05:10 AM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 05:39 AM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 05:43 AM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 09:03 AM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 09:28 AM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 11:33 AM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 08:00 PM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 09:47 PM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-19-2009, 11:46 PM
Best way to handle authentication with MY_Controller ? - by El Forum - 09-20-2009, 05:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB