I'm a beginner in Symfony2. Now I try to finish writing authorisation, using FOSUserBundle. I have a problem, that authorised user can access to log in page or register page. Can I change this in configs or I have to check it in the controller? Thank you
PS I mean such part in security.yml:
access_control:
- { path: /new, role: ROLE_USER }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
You can solve it by creating an event listener which will hook into the FOSUserBundle controllers. For registration you could use fos_user.registration.initialize event. In your listener you could check if user is already authenticated, if yes then redirect to whatever route you like (e.g. to homepage). See this answer to see the example.
For login route (/login) you could override the default FOSUserBundle SecurityController and check there if user is authenticated and do the redirect. See this example.
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