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

[eluser]n0xie[/eluser]
I don't know if you meant you didn't understand how we could override the default behaviour if a controller is protected by default but here is an example in its most basic form. Maybe someone can learn something from it.

Code:
class Frontend_Controller extends Controller {
    
    protected $public = FALSE;

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

        if($this->public === TRUE)
        {
            // open for public access
        }
        else
        {
            $this->load->library('auth');
            if ($this->auth->is_loggedin() === FALSE)
            {
                redirect(site_url('login'));
            }

        }
      }

class Somecontroller extends Frontend_Controller {

    // allow public access
        protected $public = TRUE;
    
    function Somecontroller()
    {
        parent::Frontend_Controller();
    }

This could easily be extended to have an 'allowed method' list using the same convention so you can allow some methods(pages) to be publicly available or add admin rights checks if you want to :
Code:
protected $public_methods = array();

The easy part is that if you don't specifically set public to TRUE, it defaults to FALSE, following the logic of white listing, instead of blacklisting basically disallowing everything by default unless specifically overruled.


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