CodeIgniter Forums
Need to authenticate an user and redirect him to the requested page: possible? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Need to authenticate an user and redirect him to the requested page: possible? (/showthread.php?tid=34491)



Need to authenticate an user and redirect him to the requested page: possible? - El Forum - 10-01-2010

[eluser]LeonardoGaiero[/eluser]
Greetings, all. I have a question: in the application I'm developing, I have the necessity to authenticate an user when they open a link to a resource.

Currently, I have in place a check that redirects the user to the main page in case of a new session, which does the auth by populating the session data; however, what I wish to do is to redirect them immediately to the requested resource upon authentication success, rather than dumping them to the main page.

Auth happens automatically according to LDAP data, so the user doesn't have to input his credentials in order to access the system: everything that's needed to start the session comes directly from the DC, so all I need is a way to authenticate them and load the requested URL straight up. How would I go about doing this in a clean, easy way? Thanks in advance.


Need to authenticate an user and redirect him to the requested page: possible? - El Forum - 10-01-2010

[eluser]Ki[/eluser]
What about passing the resource link in the url to the controller that handles authentication and then redirect to that url. You can pass it as /login/redirect/new/url/to/redirect/to/
Then, once authentication complete, extract everything after /redirect/ and do a redirect() to it.
Is that something you are looking for?


Need to authenticate an user and redirect him to the requested page: possible? - El Forum - 10-01-2010

[eluser]LeonardoGaiero[/eluser]
[quote author="Ki" date="1285950520"]What about passing the resource link in the url to the controller that handles authentication and then redirect to that url. You can pass it as /login/redirect/new/url/to/redirect/to/
Then, once authentication complete, extract everything after /redirect/ and do a redirect() to it.
Is that something you are looking for?[/quote]

Thanks for your response. I like that solution, partly due to the fact that the application manages separate roles according to the current user's privileges and I don't know beforehand which role is going to be loaded for who; at this point, I could create a redirect role to parse out the link and redirect the user to the right controller/function.

Thanks again for tipping me in the right direction, I'll post snippets if I come up with something worth sharing.


Need to authenticate an user and redirect him to the requested page: possible? - El Forum - 10-01-2010

[eluser]Ki[/eluser]
Glad to help.
I used something like this for one of my solutions where I had one section that displayed list of locations and changed the user location. But after that change, I wanted to be able to send the user back to the page where he/she came from to change the location specification. So, from every link, leading to the location change page, I added redirect clause. Example (/map/view/redirect/products/category/1). Now withing my map controller view method I had something like
function view($redirect == FALSE){
if($redurect != FALSE)
// find "/redirect/" in uri string and get everything after it with substr(). This becomes your return/redirect URI

}