FOSUserBundle : Redirect the user after register with EventListener

To accomplish what you want, you should use FOSUserEvents::REGISTRATION_CONFIRM instead of FOSUserEvents::REGISTRATION_CONFIRMED. You then have to rewrite rewrite your class RegistrationConfirmedListener like: class RegistrationConfirmListener implements EventSubscriberInterface { private $router; public function __construct(UrlGeneratorInterface $router) { $this->router = $router; } /** * {@inheritDoc} */ public static function getSubscribedEvents() { return array( FOSUserEvents::REGISTRATION_CONFIRM => ‘onRegistrationConfirm’ ); } public … Read more

Symfony: How do I refresh the authenticated user from the database?

Try this: $em = $this->getDoctrine()->getManager(); $loggedInUser = $this->get(‘security.context’)->getToken()->getUser(); $loggedInUser->addRole(‘ROLE_XYZ’); $em->persist($loggedInUser); $em->flush(); $token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken( $loggedInUser, null, ‘main’, $loggedInUser->getRoles() ); $this->container->get(‘security.context’)->setToken($token);

Remove / Replace the username field with email using FOSUserBundle in Symfony2 / Symfony3

A complete overview of what needs to be done Here is a complete overview of what needs to be done. I have listed the different sources found here and there at the end of this post. 1. Override setter in Acme\UserBundle\Entity\User public function setEmail($email) { $email = is_null($email) ? ” : $email; parent::setEmail($email); $this->setUsername($email); return … Read more

How to customize FOS UserBundle URLs

How to override / change FOSUserBundle’s routes You can override i.e the /register route in your app/config/routing.yml by re-declaring it after importing FOSUserBundle’s XML routes as resources. fos_user_register: resource: “@FOSUserBundle/Resources/config/routing/registration.xml” prefix: /register # … fos_user_registration_register: path: /account/register defaults: { _controller: FOSUserBundle:Registration:register } … or just change the prefix when importing: fos_user_register: resource: “@FOSUserBundle/Resources/config/routing/registration.xml” prefix: /account/register … Read more

Symfony2 AJAX Login

David’s answer is good, but it’s lacking a little detail for newbs – so this is to fill in the blanks. In addition to creating the AuthenticationHandler you’ll need to set it up as a service using the service configuration in the bundle where you created the handler. The default bundle generation creates an xml … Read more