Viewed   64 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?

 Answers

1

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"/>
</service>

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'));
        }

        $event->setResponse($response);
    }
}
Thursday, November 10, 2022
2

You need to give the array_shift() the parameter! Look this example:

$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_shift($stack); // Here you give the parameter
print_r($fruit);

You give the null parameter on array_shift() and you need to change it!

Update:

array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All numerical array keys will be modified to start counting from zero while literal keys won't be touched. Read here for more

Wednesday, October 19, 2022
 
shark
 
5

file_put_contents creates the file if it doesn't exist, but it fails if you try to put the file in a directory that doesn't exist. So you should try the following:

  • check if the images directory exists
  • check the write permissions of the directory
  • try with an absolute path, so in your case probably $target_dir = '/home/ragiththomas/Sites/asco-forum/images/';
Friday, December 9, 2022
5

@Danial check this code

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference("users");
rootRef.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    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));
                              }
        }
  
    }

    @Override
    public void onCancelled(@NonNull DatabaseError error) {

    }
});
Monday, September 5, 2022
28

Apache's mod_proxy could, in fact, do exactly what you want.

Its session-stickiness reads from cookie values; if all of the application servers know which server a user needs to go to (I'm not really clear on how the user distribution is decided, but we'll assume that it's stored or calculable), then it's simple.

Any server could give the user their server cookie on the first request. Say apache throws them to internal1, but they should be on internal2; the cookie can be something like SERVERID set to server.internal2. On the second request, with the below config, apache will see the cookie and send the user to the BalancerMember backend that is attached to the route defined in the cookie.

<Proxy balancer://domain>
    BalancerMember http://internal1.domain.com route=internal1
    BalancerMember http://internal2.domain.com route=internal2
</Proxy>

ProxyPass / balancer://domain/ stickysession=SERVERID
ProxyPassReverse / balancer://domain/
Sunday, September 18, 2022
 
mezulu
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :