Reputation: 65
I'm trying to create a form for registering new user without defining their password. The idea is to save the new user and then asking to change the password through the reset password procedure from fos user bundle.
I can't figure how I can trigger the procedure for resetting password in my controller.
Here is the submission part of my controller :
if ($request->getMethod() === 'POST') {
$form->bind($request);
if ($form->isValid()) {
$tokenGenerator = $this->get('fos_user.util.token_generator');
$password = substr($tokenGenerator->generateToken(), 0, 8);
$user->setEnabled(false);
$user->setPlainPassword($password);
/** @var $dispatcher EventDispatcherInterface */
$dispatcher = $this->container->get('event_dispatcher');
$event = new GetResponseUserEvent($user, $request);
$userManager->updatePassword($user);
$userManager->updateUser($user);
$em->persist($user);
$em->flush();
// Is this isn't supposed to send an email to the newly created user asking to change his password ?
$dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_REQUEST, $event);
return new RedirectResponse($this->generateUrl('some_url'));
}
}
As commented in the code :
Is this isn't supposed to send an email to the newly created user asking to change his password ?
$dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_REQUEST, $event);
Upvotes: 1
Views: 899
Reputation: 17906
Maybe it helps you i solved it this way
set the new password with usermanager
$userManager = $this->get('fos_user.user_manager');
$entity->setPlainPassword("123");
$userManager->updateUser($entity);
Upvotes: 1