Skip to content

Commit 4becccc

Browse files
committed
Added an event before confirming the account
1 parent ddbb2dc commit 4becccc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Controller/RegistrationController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,19 @@ public function confirmAction($token)
101101
throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token));
102102
}
103103

104+
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
105+
$dispatcher = $this->container->get('event_dispatcher');
106+
104107
$user->setConfirmationToken(null);
105108
$user->setEnabled(true);
106109
$user->setLastLogin(new \DateTime());
107110

111+
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRM, new UserEvent($user));
112+
108113
$this->container->get('fos_user.user_manager')->updateUser($user);
114+
109115
$response = new RedirectResponse($this->container->get('router')->generate('fos_user_registration_confirmed'));
110116

111-
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
112-
$dispatcher = $this->container->get('event_dispatcher');
113117
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRMED, new UserResponseEvent($user, $response));
114118

115119
return $response;

FOSUserEvents.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ final class FOSUserEvents
4040
*/
4141
const REGISTRATION_COMPLETED = 'fos_user.registration.completed';
4242

43+
/**
44+
* The REGISTRATION_CONFIRM event occurs just before confirming the account.
45+
*
46+
* This event allows you to access the user which will be confirmed.
47+
* The event listener method receives a FOS\UserBundle\Event\UserEvent instance.
48+
*/
49+
const REGISTRATION_CONFIRM = 'fos_user.registration.confirm';
50+
4351
/**
4452
* The REGISTRATION_CONFIRMED event occurs after confirming the account.
4553
*

0 commit comments

Comments
 (0)