Welcome Guest, Not a member yet? Register   Sign In
Login check, stop requested operation if not logged in
#1

[eluser]mvdg27[/eluser]
Hi,

I though I had found a smart way to automatically check if a user is logged in, for every operation. But I've run into some problems.

I have created a very simple library, that is autoloaded. In the constructer it checks if a valid user session exists. If it doesn't, I loads a view file (which contains a piece of javascript, with the login prompt).

This is working, except for the fact that it also performs the requested operation, which off course is not the desired behaviour. So I'm actually looking for a way to stop the rest of the script if the login window is launched. So far I've tried to add an exit() or die() statement in my library, but then the view is never loaded, off course. I can always add a check in every function, with an if else construction, but that's just a whole lot of extra code, for every function. I liked the fact that regardless of the function, it always checked for the session, through the autoloaded library.

I have already thought of redirecting instead of loading a view, but the thing is I'm working with the Ext-JS library. So it would be nice to keep the user in the existing Ext-JS environment and after a succesful re-login, continue his work.

I hope you guys understand my train of thought. Someone can think of any solution for this?


Thanks in advance, Michiel
#2

[eluser]Pascal Kriete[/eluser]
A redirect is the best choice here. If you're not loading any other views, you could do this:
Code:
echo $this->load->view('login', array(), TRUE);
exit;




Theme © iAndrew 2016 - Forum software by © MyBB