Using latest Symfony and FOSUserbundle, after successfully registering a new user, the user is automatically logged in. I want to prevent this. My reason is that only a special user should be able to register new users.
I guess I have to override the registerAction in the RegisterController of the bundle, but I don't know how.
I tried: http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_controllers.html, but it seems to be outdated, no user is created with this method.
Any hints are appreciated.
Edit:
I found out that I did not create the child bundle correctly. I also had to create my own EventListener. It works now when I overwrite the FOSUserEvents::REGISTRATION_SUCCESS
event.
Strange thing is that when I use the FOSUserEvents::REGISTRATION_COMPLETED
event, both events are dispatched, my bundle's and the FOSUserbundle's, so that the user is redirected to the correct site, but logged in as the new user.
Edit 2:
So this is in my listener:
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess',
FOSUserEvents::REGISTRATION_COMPLETED => 'onRegistrationCompleted',
);
}
public function onRegistrationSuccess(FormEvent $event)
{
$url = $this->router->generate('admin');
$event->setResponse(new RedirectResponse($url));
}
public function onRegistrationCompleted(FilterUserResponseEvent $event)
{
}
I set the redirection in the REGISTRATION_SUCCESS
event and the REGISTRATION_COMPLETED
is empty. With the debugger I can verify that my own listener's event is called, but the original event is also called.
Actually, there is no need to do any of these. The fos_user.listener.authentication
service is removed from the container if use_authentication_listener
is set to false.
See line 74-76 in FOS\UserBundle\DependencyInjection\FOSUserExtension
.
This information is also included in document FOS UserBundle Configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With