Welcome Guest, Not a member yet? Register   Sign In
Authentication check for admin website
#1

[eluser]deed02392[/eluser]
Hi guys. I'm creating a web application where every single page load would require the user is authenticated. So far I have just been including an 'is_logged_in' check for every single method of all the controller classes but this seems like madness.

Is there somewhere in the framework which supports authenticating the user on a higher level, such that I can simply assume the user is authenticated if one of my controllers is loaded?

Thanks!
#2

[eluser]CroNiX[/eluser]
Create a MY_Controller and have all of your other controllers extend that instead of CI_Controller. In the construct of MY_Controller you can put your auth.
http://ellislab.com/codeigniter/user-gui...asses.html
#3

[eluser]deed02392[/eluser]
That's a great idea. Thanks very much.
#4

[eluser]deed02392[/eluser]
Hmm on this point, what about defining common information like the logged in username and user ID? I guess the best place to declare this is in the constructor of MY_Controller, but then it isn't accessible to the views when they're called in. What can I do about that?
#5

[eluser]CroNiX[/eluser]
$this->load_vars($data) makes it available to all views
#6

[eluser]deed02392[/eluser]
Looks like that's undocumented, do you mean to use it in the controller to specify it as a global or to set $data elements in the controller and use
Code:
$this->load_vars($data)
from views, or page controllers before views are loaded etc?
#7

[eluser]Aken[/eluser]
It's documented in the Loader Class. Except it would be $this->load->vars($data). You'd call it in your controller.
#8

[eluser]Mauricio de Abreu Antunes[/eluser]
Save those informations in sessions.




Theme © iAndrew 2016 - Forum software by © MyBB