Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to the requested URI after authentication using Zend_Auth?

I am using a simple Zend_Auth setup to authenticate users for one of my applications, using a check in the preDispatch() method in a controller plugin. When anonymous users navigate to

/users/view/id/6

for example, they should be redirected to the above URI after authentication.

What is the best way to do this? I'd prefer not to store $_SERVER['REQUEST_URI'] in the session. Personally, I'd find storing the entire Zend Request object to cleanest solution, but I am not sure if this is sensible and if this is the approach I should be taking.

Any thoughts?

like image 795
Aron Rotteveel Avatar asked Nov 06 '22 22:11

Aron Rotteveel


1 Answers

Well redirecting or forwarding to the LoginController might not be the optimal way to bring an un-authenticated user to the login page. Instead at preDispatch you can grab the $request object and alter it by doing the following.

$request->setActionName('someaction');
$request->setControllerName('somecontroller');

At this point your original request in maintained yet the page is displaying the login page. Then you can alter your login controller to check to see if the current request location is the login controller or if it something else. If it is something else (the original request) on a successful login send them to that page.

like image 125
danielrsmith Avatar answered Nov 12 '22 15:11

danielrsmith