-
-
Save gencer/6180d89306471ab9c84e to your computer and use it in GitHub Desktop.
Custom FOSUB redirects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace My\Bundle\EventListener; | |
use My\Bundle\User\User; | |
use Symfony\Component\Routing\Router; | |
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | |
class InteractiveLoginListener | |
{ | |
/** | |
* @var \Symfony\Component\Routing\Router | |
*/ | |
private $router; | |
/** | |
* @param \Symfony\Component\Routing\Router $router | |
*/ | |
public function __construct(Router $router) | |
{ | |
$this->router = $router; | |
} | |
/** | |
* @param \Symfony\Component\Security\Http\Event\InteractiveLoginEvent $event | |
*/ | |
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) | |
{ | |
$user = $event->getAuthenticationToken()->getUser(); /** @var \My\Bundle\User\User */ | |
$request = $event->getRequest(); /** @var \Symfony\Component\HttpFoundation\Request $request */ | |
if ($user instanceof User) { | |
$request->request->set('_target_path', $this->router->generate('my_custom_route', array('_locale' => 'en'))); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<container xmlns="http://symfony.com/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |
<services> | |
<service id="my.security.interactive_login_listener" class="My\Bundle\EventListener\InteractiveLoginListener"> | |
<argument type="service" id="router" /> | |
<tag name="kernel.event_listener" event="security.interactive_login" method="onSecurityInteractiveLogin" priority="255" /> | |
</service> | |
</services> | |
</container> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment