Login / Auth function always checked |
[eluser]internut[/eluser]
Sorry if I've missed this. If so would you please point me in the right direction? I'm progressing well but am looking at how I can first make sure a session var is set before progressing and allowing functions to run. Basically a login check function that is called and checks if user is logged in before moving around functions / controllers. noob I know.
[eluser]internut[/eluser]
would this be not the right way to go about it at the beginning of each controller function: Code: if(!$this->session->userdata('logged_in')) {
[eluser]Aea[/eluser]
You could always create a function i.e. $this->auth->user_only() that you can call through the controller and that'll check if the user is logged in.
[eluser]internut[/eluser]
[quote author="Aea" date="1214462823"]You could always create a function i.e. $this->auth->user_only() that you can call through the controller and that'll check if the user is logged in.[/quote] Meaning: Controller: auth.php function within it of: Code: function user_only { I'm pretty sure I'm off. Any pointers greatly appreciated. Trying to understand where the function should go (if i'm wrong) and how to call it. Or is there a better way to before any controller / function is executed to first check a login.
[eluser]Aea[/eluser]
Create a library/plugin/helper that's loaded globally and then create a function that'll do your session check and then call that from the controller you want to be user_only. A more elaborate method would be having this function get the page url, then redirect if the user isn't logged in, once the user is logged then you can redirect back
[eluser]internut[/eluser]
Its basically this: Login Page ---> Rest of program here (not a few functions / controllers but all) So should I go crazy with creating a function or just place the following in each function: Code: if(!$this->session->userdata('logged_in')) {
[eluser]Chris Newton[/eluser]
Michael Wales uses a good method. Extend the controller class with something like Public_controller and Admin_controller. The public controller / admin controller looks up whether the user is logged in. If you want someone to be able to use a specific controller, make it publig, otherwise make it an admin controller, or loggedin_controller, etc. Search for Erkana Auth.
[eluser]internut[/eluser]
Found: http://codeigniter.com/wiki/Erkana/ Tho the link: http://www.michaelwales.com/wp-content/u...naauth.zip Is no longer avail.... hmmm
[eluser]Chris Newton[/eluser]
He has the entire thing in posted here in the forums. It's pretty small. http://ellislab.com/forums/viewreply/338903/ |
Welcome Guest, Not a member yet? Register Sign In |