Using FOSUserBundle and Symfony2,
in my site, depending on the roles of the user that is logged in, I want to make the Logout to redirect alternatively to two different pages.
So, I want to do something like this:
{% if is_granted("ROLE_PREMIUM") %}
<a href="{{ path('fos_user_security_logout_premium') }}">{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}</a>
{% else %}
<a href="{{ path('fos_user_security_logout') }}">{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}</a>
{% endif %}
And then, somehow, do something like this:
<route id="fos_user_security_logout" pattern="/logout">
<default key="_controller">FOSUserBundle:Security:logout</default>
</route>
<route id="fos_seller_security_logout" pattern="/logoutPremium">
<default key="_controller">FOSUserBundle:Security:logoutPremium</default>
</route>
But, since all in logout is done in config.yml, putting all this configuration about login and logout, I don’t know how to configure a second trigger and implement it. Actually, the only thing that I want to do is to redirect the user to two different pages according to the role. All the rest should stay the same.
Anything to put around here in security.yml?
logout:
path: /logout
target: /main/user
Thanks a lot
You can add a
CustomLogoutHandlerto yoursecurity.ymlconfiguration.Where
your_bundle.custom_logout_handlerwould be in charge to logout your user and redirect him according to a similar _target_url parameter for example.See
Symfony/Component/Security/Http/Logout