I want to redirect the user to another form just after registration, before he could access to anything on my website (like in https://github.com/FriendsOfSymfony/FOSUserBun
If you're not using a confirmation email, you can redirect the user right after submiting the registration form this way :
class RegistrationConfirmationSubscriber implements EventSubscriberInterface
{
/** @var Router */
private $router;
public function __construct(Router $router)
{
$this->router = $router;
}
public static function getSubscribedEvents()
{
return [FOSUserEvents::REGISTRATION_COMPLETED => 'onRegistrationConfirm'];
}
public function onRegistrationConfirm(FilterUserResponseEvent $event)
{
/** @var RedirectResponse $response */
$response = $event->getResponse();
$response->setTargetUrl($this->router->generate('home_route'));
}
}
The subscriber declaration stay the same :
registration_confirmation_subscriber:
class: AppBundle\Subscriber\RegistrationConfirmationSubscriber
arguments:
- "@router"
tags:
- { name: kernel.event_subscriber }