Symfony Action Security - How to forward after successful authentication?
The first time you access your login action, store the referent in the user session:
if(!$this->getUser()->hasParameter('referer'))
{
$this->getUser()->setParameter('referer',$this->getRequest()->getReferer());
}
and then on successful login, redirects the user to the saved referent with:
$this->redirect($this->getUser()->getParameter('referer'));
You have a complete example in sfGuardPlugin:
source to share
Related issue, but instead trying to forward from another action:
If you have an action protected by sfGuard that tries to redirect to a referrer, you will get a redirect loop after login. This is because the sfGuard login page wil becomes the referee. A parameter or attribute can be saved across multiple requests if it is stored in the login action as above, which means the action might be redirected to an invalid page if it is already enabled. The solution is to use a flash to be forgotten. This can be accomplished with the following code in the executeSignin method for sfGuardAuthActions:
if ($this->getUser()->hasFlash('referer'))
{
$this->getUser()->setFlash('referer', $this->getUser()->getFlash('referer'));
}
else
{
$this->getUser()->setFlash('referer', $this->getRequest()->getReferer());
}
By dumping the flash in the first block, it will not be forgotten between login attempts, and with flash, login from other pages cannot interfere with your action.
source to share