I'm trying to implement registeration with FOSUserBundle. I want an admin to be able register a new user and this I've done simply by changing registration to a firewalled route (/admin/register prefix).
I created a custom registration form type and registered it as a service as instructed here: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md
I then hooked into the registration events based on this: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/controller_events.md
My listener looks like this:
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class RegistrationListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_COMPLETED => 'onRegisterDone',
FOSUserEvents::REGISTRATION_CONFIRMED => 'onRegisterDone',
FOSUserEvents::RESETTING_RESET_COMPLETED => 'onRegisterDone',
);
}
public function onRegisterDone(FilterUserResponseEvent $event)
{
$url = $this->router->generate('admin_panel');
//$event->setResponse(new RedirectResponse($url));
}
}
The FilterUserResponseEvent does not have the setResponse method, so I'm just letting it run through. I thought that subscribing to this event would override the default FOS\UserBundle\EventListener\AuthenticationListener subscribed events and stop the user from being logged in, but the new user still gets logged in.
Is it possible to prevent the authentication, or should I just simply create a new form which would call an action to call User Manager?