0

I tryed for 3 days to make a redirection in FOSUser to redirect logged people to index if they try to access the login page, but unfortunately it's seems that there are no way to do this.

How can I do this ?

j0k
  • 22,600
  • 28
  • 79
  • 90
tannana
  • 121
  • 3
  • 10

3 Answers3

1

This little extension in the loginAction should do the trick..

$user = $this->container->get('security.context')->getToken()->getUser()
if (is_object($user) && $user instanceof UserInterface) {
    return  new RedirectResponse($this->container->get('router')->generate('_your_route'));
}
weyandch
  • 644
  • 6
  • 14
0

You can override FOSUserBundle SecurityController loginAction() method. Inside, check if the user is connected with $this->container->get('security.context')->getToken()->getUser(); and redirect with $this->redirect if needed.

fkoessler
  • 6,932
  • 11
  • 60
  • 92
  • 1
    The probleme is that when im logged an i go to login page, i become anononymous !so if i test with is_object($this->get('security.context')->getToken()->getUser()) it doesnt work ! – tannana Dec 03 '12 at 11:51
0

This can be done with default_target_path in firewall configuration:

security:
    firewalls:
    somename:
        form_login:
            default_target_path: /your-desired-path

Find the official description in the book: http://symfony.com/doc/current/reference/configuration/security.html#form-login-configuration

Marc Juchli
  • 2,240
  • 24
  • 20