Asked  7 Months ago    Answers:  5   Viewed   30 times

I have one login page on site. I have 4 different tye of users and i want that when they login they go to different page based on their role assigned.

Is there any way?



One way to solve this is to use an event listener on the security.interactive_login event. In this case I simply attach another listener in that event listener so it will fire on the response. This lets the authentication still happen but still perform a redirect once complete.

<service id="sotb_core.listener.login" class="SOTBCoreBundleEventListenerSecurityListener" scope="request">
    <tag name="kernel.event_listener" event="security.interactive_login" method="onSecurityInteractiveLogin"/>
    <argument type="service" id="router"/>
    <argument type="service" id="security.context"/>
    <argument type="service" id="event_dispatcher"/>

And the class...

class SecurityListener
    protected $router;
    protected $security;
    protected $dispatcher;

    public function __construct(Router $router, SecurityContext $security, EventDispatcher $dispatcher)
        $this->router = $router;
        $this->security = $security;
        $this->dispatcher = $dispatcher;

    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
        $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));

    public function onKernelResponse(FilterResponseEvent $event)
        if ($this->security->isGranted('ROLE_TEAM')) {
            $response = new RedirectResponse($this->router->generate('team_homepage'));
        } elseif ($this->security->isGranted('ROLE_VENDOR')) {
            $response = new RedirectResponse($this->router->generate('vendor_homepage'));
        } else {
            $response = new RedirectResponse($this->router->generate('homepage'));

Wednesday, March 31, 2021
answered 7 Months ago

You need to put any strings starting with @ in quotes:

    ["@security.context", "@fos_user.user_manager"]

Reserved characters, like @, should be quoted. Unquoted @s were deprecated in Symfony 2.8. Symfony 3.0 will forbid you to use such definitions and will throw an exception.

If you don't have control over the bundle that registered the problematic configuration, send a pull request with a fix to the vendor. As a quick fix you can downgrade Symfony. 2.7 will work, as well as 2.8 (the later will only emit a deprecation notice).

Saturday, May 29, 2021
answered 5 Months ago

I ran into the same issue and found the following solution in the documentation:

To run your functional tests, the WebTestCase class bootstraps the kernel of your application. In most cases, this happens automatically. However, if your kernel is in a non-standard directory, you'll need to modify your phpunit.xml.dist file to set the KERNEL_DIR environment variable to the directory of your kernel:

    <!-- ... -->
        <server name="KERNEL_DIR" value="/path/to/your/app/" />
    <!-- ... -->

So check your phpunit.xml.dist configuration file and try to add the absolute path to your app-directory.

Hope it helps.

Friday, July 30, 2021
Bálint Molnár
answered 3 Months ago

Use: and press enter/control+K

and after this, even if you try / google and press control+K, it'll work and won't redirect to

Sunday, August 22, 2021
answered 2 Months ago

@Danial check this code

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference("users");
rootRef.addListenerForSingleValueEvent(new ValueEventListener() {
    public void onDataChange(@NonNull DataSnapshot snapshot) {
        for (DataSnapshot dataSnapshot:snapshot.getChildren()){
            String mail=dataSnapshot.child("type").getValue().toString();
             if (userType.equals("Buyer")) {
          startActivity(new Intent(MainActivity.this,BuyerHomepage.class));
                            if(userType.equals("Seller")) {
           startActivity(new Intent(MainActivity.this,SellerHomepage.class));

    public void onCancelled(@NonNull DatabaseError error) {

Monday, August 30, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :