I've the following problem in my symfony 2 application.
When a user is already is logged in he still has access to the route /login. What is the best way to avoid this case ?
I tried to redirect the user if he wants to login, but this didn't works, as i thought.
public function loginAction()
{
if (!$this->get('security.context')->isGranted('ROLE_USER')) {
// not logged in
...
code
...
..
.
} else {
// already logged in
$this->redirect($this->generateUrl('HereIsMyRouteName'));
}
}
I solved it on my own, the problem was that I have to return the redirect.
return $this->redirect($this->generateUrl('HereIsMyRouteName'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With