From 0f0e8eb82a3374e20453fb1f8046325ee306b036 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 21 Jan 2016 16:39:13 +0100 Subject: Use FOSUserEvents instead of c/p a controller The `resetAction` was overriden to redirect user to the homepage instead of `fos_user_profile_show`. Instead of copying the whole method we can simply use FOSUserEvents to handle that. --- .../UserBundle/Controller/ResettingController.php | 75 ---------------------- .../EventListener/PasswordResettingListener.php | 41 ++++++++++++ .../UserBundle/Resources/config/services.yml | 7 ++ 3 files changed, 48 insertions(+), 75 deletions(-) delete mode 100644 src/Wallabag/UserBundle/Controller/ResettingController.php create mode 100644 src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php (limited to 'src/Wallabag/UserBundle') diff --git a/src/Wallabag/UserBundle/Controller/ResettingController.php b/src/Wallabag/UserBundle/Controller/ResettingController.php deleted file mode 100644 index 62e27d00..00000000 --- a/src/Wallabag/UserBundle/Controller/ResettingController.php +++ /dev/null @@ -1,75 +0,0 @@ -get('fos_user.resetting.form.factory'); - /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); - - $user = $userManager->findUserByConfirmationToken($token); - - if (null === $user) { - throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $token)); - } - - $event = new GetResponseUserEvent($user, $request); - $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_INITIALIZE, $event); - - if (null !== $event->getResponse()) { - return $event->getResponse(); - } - - $form = $formFactory->createForm(); - $form->setData($user); - - $form->handleRequest($request); - - if ($form->isValid()) { - $event = new FormEvent($form, $request); - $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_SUCCESS, $event); - - $userManager->updateUser($user); - - if (null === $response = $event->getResponse()) { - $this->get('session')->getFlashBag()->add( - 'notice', - 'Password updated' - ); - $url = $this->generateUrl('homepage'); - $response = new RedirectResponse($url); - } - - $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_COMPLETED, new FilterUserResponseEvent($user, $request, $response)); - - return $response; - } - - return $this->render('FOSUserBundle:Resetting:reset.html.twig', array( - 'token' => $token, - 'form' => $form->createView(), - )); - } -} diff --git a/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php b/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php new file mode 100644 index 00000000..2fdcb441 --- /dev/null +++ b/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php @@ -0,0 +1,41 @@ +router = $router; + } + + /** + * {@inheritDoc} + */ + public static function getSubscribedEvents() + { + return array( + FOSUserEvents::RESETTING_RESET_SUCCESS => 'onPasswordResettingSuccess', + ); + } + + public function onPasswordResettingSuccess(FormEvent $event) + { + $url = $this->router->generate('homepage'); + + $event->setResponse(new RedirectResponse($url)); + } +} diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml index 93e04d59..bf9e036a 100644 --- a/src/Wallabag/UserBundle/Resources/config/services.yml +++ b/src/Wallabag/UserBundle/Resources/config/services.yml @@ -8,3 +8,10 @@ services: - "%scheb_two_factor.email.sender_name%" - "%wallabag_support_url%" - "%wallabag_url%" + + wallabag_user.password_resetting: + class: Wallabag\UserBundle\EventListener\PasswordResettingListener + arguments: + - "@router" + tags: + - { name: kernel.event_subscriber } -- cgit v1.2.3