Question

I use the FOSUser Bundle as a basis class for my own User class. Through a webservice it's possible to create new users.

As far as I know it's only triggered when a user registers himself through the registration form.

Is there a way to manual trigger the confirmation email from a controller?

Was it helpful?

Solution 2

It seems like there is no solution to manually trigger the dispatch of the confirmation email. It's only triggered in combination with the registration form. What I ended up doing is to fake a form and the dispatch of it to trigger the event listener responsible for the dispatch of the email.

//use FOS\UserBundle\FOSUserEvents;
//use FOS\UserBundle\Event\FormEvent;

$formFactory = $this->get('fos_user.registration.form.factory');
$form = $formFactory->createForm();
$form->setData($user); // created user object
$event = new FormEvent($form, $request); // request of the Controller
$dispatcher = $this->get('event_dispatcher');
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);

Not really a clean solution, but the only one I could come up with, as the FOSUserBundle doesn't seem to offer any kind of API for it.

OTHER TIPS

This worked for me

$mailer = $this->container->get('fos_user.mailer');
// Create token
$token = sha1(uniqid(mt_rand(), true)); // Or whatever you prefer to generate a token
$user->setConfirmationToken($token);
$mailer->sendConfirmationEmailMessage($user);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top