CodeIgniter Forums

Full Version: User Authentication?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Moon 111[/eluser]
Hi, I'm new to CodeIgniter and I was wondering if you had something built in where you can define in the controller who is allowed to access the page.

Anything like that built in?

Thanks

El Forum

[eluser]Randy Casburn[/eluser]
There are a lot of alternatives.

Many are open source and you can find those in the Wiki.

I've also just released a commercial drop in you can find here: Plurious Auth

and there is one called Webber that is much different that can be found here: http://www.drsoft.com/

hope this helps,

Randy

El Forum

[eluser]Moon 111[/eluser]
No, I think you misunderstood me.

I would want to have a setup like this (all classes are together to make it easier):

Code:
<?php

Abstract Class Auth Extends Controller {

    public function __construct() {
        
        parent::__construct();
    }
    
    abstract public function authenticate();
}

Class Auth_None Extends Auth {

    public function authenticate() {
    
        return true;
    }
}

Class Auth_User Extends Auth {

    public function authenticate() {
    
        // If logged in return true, else false
    }
}

// etc...

?>

And the controllers would extends Auth_None or Auth_User. In index.php it would check if autenticate returned true and if it didn't it would return an error page...

El Forum

[eluser]Randy Casburn[/eluser]
Sorry, let me answer your question more directly.

No, there is no authentication built into CI at all. You must seek an alternative elsewhere. From a third party source.

Hope that answers your first question. Sorry to confuse you.

Randy

El Forum

[eluser]Moon 111[/eluser]
Could I stick that code into the model folder? Where would it check if authenticate returns true?

Thanks

El Forum

[eluser]manilodisan[/eluser]
Codeigniter's way of loading classes and forcings will stay in your way if you wish to add multiple classes in the same file and load them through the usual "$this->load->library". We use an external folder called "scripts" to place there such libraries and other scripts we use however, if I'm reading correctly, your vision of an application would conflict with CI badly from the first lines...why use a framework like this if you're not willing to adhere to it's coding...

El Forum

[eluser]Rick Jolly[/eluser]
Create a file in "libraries" called MY_Controller.php. CI will include that file so all your controller classes will be available.

Some examples:
http://ellislab.com/forums/viewthread/90763/#458617
http://ellislab.com/forums/viewthread/70011/#345154

I prefer just to include/require the parent controller classes at the top of the child controller. Simple and transparent. It's just php.