In my Symfony application I am using the FOSUserBundle.
It's an application involved two main Roles of User: Factory as ROLE_FACTORY
and Custommer as ROLE_CUSTOMER
.
I have a main page for non-connected user, it's the home page of the application.
But when User is going to be connected or is connected, following the role he has, the home page has to change.
So the fos user login action have to redirect to the right page.
ROLE_FACTORY
have to be redirect to the factory_homepage
route.
ROLE_CUSTOMER
have to be redirect to the customer_homepage
route.
How can I create this behavior in the best practice using Symfony
and FOSUSerBundle
.
First off there is no best practice for this. So I leave that decision of selecting one of these options to you whichever suits you according to your needs.
OPTION 1:
You have to implement an
EventListener
in this case.STEP 1)
Register a serviceSTEP 2)
YourEventListener
itselfOPTION 2:
You can modify the vendor code at FOSUserBundle\Controller\SecurityController Add the following piece of code to make your
loginAction
look like this