title: how to redirect after login success by using EventListener
body: <p>I have a problem in the code of event listener because i need to make a EventListener  when i login as type 1 ==>redirect to:</p>
  
  <pre><code> return $this-&gt;redirect($this-&gt;generateUrl('demands_patient')); 
  </code></pre>
  
  <p>else redirect to another  path .And this is the code of loginlistener</p>
  
  <p>
  
  <pre><code>use Doctrine\ORM\Event\LifecycleEventArgs;
  use Register\UserBundle\Entity\User;
  use FOS\UserBundle\FOSUserEvents;
  use FOS\UserBundle\Event\FormEvent;
  use FOS\UserBundle\Event\GetResponseUserEvent;
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  use Symfony\Component\HttpFoundation\RedirectResponse;
  use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  use Symfony\Component\Security\Core\AuthenticationEvents;
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  class LoginListener implements EventSubscriberInterface
  {
       private $router;
  
      public function __construct(UrlGeneratorInterface $router)
      {
          $this-&gt;router = $router;
      }
  
  
      public static function onSecurityInteractiveLogin()
      {
          return array(
              FOSUserEvents::AUTHENTICATION_SUCCESS =&gt; 'redirectlogin',
          );
      }
  
      public function redirectlogin(InteractiveLoginEvent $event)
      {
          $user = $event-&gt;getUser();
  
  
           if($user-&gt;getType()=="1")
                   {
                      return $this-&gt;redirect($this-&gt;generateUrl('demands_patient')); 
                   }
           else 
                      {
                     return $this-&gt;redirect($this-&gt;generateUrl('demands')); 
                      }
      }
  }
  </code></pre>
  
  <p>and i add configuration in services.yml:</p>
  
  <pre><code>register_user.eventlistener.loginlistener:
          class: Register\UserBundle\EventListener\LoginListener
          arguments: [@router]
          tags:
              - { name: kernel.onSecurityInteractiveLogin }
  </code></pre>