aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/UserBundle/Controller')
-rw-r--r--src/Wallabag/UserBundle/Controller/ResettingController.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/Wallabag/UserBundle/Controller/ResettingController.php b/src/Wallabag/UserBundle/Controller/ResettingController.php
new file mode 100644
index 00000000..8aa1e230
--- /dev/null
+++ b/src/Wallabag/UserBundle/Controller/ResettingController.php
@@ -0,0 +1,75 @@
1<?php
2
3namespace Wallabag\UserBundle\Controller;
4
5use FOS\UserBundle\FOSUserEvents;
6use FOS\UserBundle\Event\FormEvent;
7use FOS\UserBundle\Event\GetResponseUserEvent;
8use FOS\UserBundle\Event\FilterUserResponseEvent;
9use Symfony\Component\HttpFoundation\Request;
10use Symfony\Component\HttpFoundation\RedirectResponse;
11use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
13class ResettingController extends \FOS\UserBundle\Controller\ResettingController
14{
15 /**
16 * Extends ResettingController to change the redirection after success.
17 *
18 * @param Request $request
19 * @param $token
20 *
21 * @return null|RedirectResponse|\Symfony\Component\HttpFoundation\Response
22 */
23 public function resetAction(Request $request, $token)
24 {
25 /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
26 $formFactory = $this->get('fos_user.resetting.form.factory');
27 /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
28 $userManager = $this->get('fos_user.user_manager');
29 /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
30 $dispatcher = $this->get('event_dispatcher');
31
32 $user = $userManager->findUserByConfirmationToken($token);
33
34 if (null === $user) {
35 throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
36 }
37
38 $event = new GetResponseUserEvent($user, $request);
39 $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_INITIALIZE, $event);
40
41 if (null !== $event->getResponse()) {
42 return $event->getResponse();
43 }
44
45 $form = $formFactory->createForm();
46 $form->setData($user);
47
48 $form->handleRequest($request);
49
50 if ($form->isValid()) {
51 $event = new FormEvent($form, $request);
52 $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_SUCCESS, $event);
53
54 $userManager->updateUser($user);
55
56 if (null === $response = $event->getResponse()) {
57 $this->get('session')->getFlashBag()->add(
58 'notice',
59 'Password updated'
60 );
61 $url = $this->generateUrl('homepage');
62 $response = new RedirectResponse($url);
63 }
64
65 $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
66
67 return $response;
68 }
69
70 return $this->render('FOSUserBundle:Resetting:reset.html.twig', array(
71 'token' => $token,
72 'form' => $form->createView(),
73 ));
74 }
75}