|
@@ -0,0 +1,65 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\UserBundle\Controller;
|
|
4
|
+
|
|
5
|
+use FOS\UserBundle\Controller\ResettingController as BaseResettingController;
|
|
6
|
+
|
|
7
|
+use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
8
|
+use FOS\UserBundle\Model\UserInterface;
|
|
9
|
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
10
|
+
|
|
11
|
+/**
|
|
12
|
+ *
|
|
13
|
+ * @author bux
|
|
14
|
+ */
|
|
15
|
+class ResettingController extends BaseResettingController
|
|
16
|
+{
|
|
17
|
+
|
|
18
|
+ /**
|
|
19
|
+ * Reset user password
|
|
20
|
+ */
|
|
21
|
+ public function resetAction($token)
|
|
22
|
+ {
|
|
23
|
+ $user = $this->container->get('fos_user.user_manager')->findUserByConfirmationToken($token);
|
|
24
|
+
|
|
25
|
+ if (null === $user){
|
|
26
|
+ throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ if (!$user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
|
|
30
|
+ return new RedirectResponse($this->container->get('router')->generate('fos_user_resetting_request'));
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ $form = $this->container->get('fos_user.resetting.form');
|
|
34
|
+ $formHandler = $this->container->get('fos_user.resetting.form.handler');
|
|
35
|
+ $process = $formHandler->process($user);
|
|
36
|
+
|
|
37
|
+ if ($process) {
|
|
38
|
+ $this->authenticateUser($user);
|
|
39
|
+
|
|
40
|
+ $this->setFlash('success', 'Votre mot de passe a été mis a jour avec succés.');
|
|
41
|
+
|
|
42
|
+ return new RedirectResponse($this->getRedirectionUrl($user));
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ return $this->container->get('templating')->renderResponse('FOSUserBundle:Resetting:reset.html.'.$this->getEngine(), array(
|
|
46
|
+ 'token' => $token,
|
|
47
|
+ 'form' => $form->createView(),
|
|
48
|
+ 'theme' => $this->container->getParameter('fos_user.template.theme'),
|
|
49
|
+ ));
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ /**
|
|
53
|
+ * Generate the redirection url when the resetting is completed.
|
|
54
|
+ *
|
|
55
|
+ * @param UserInterface $user
|
|
56
|
+ * @return string
|
|
57
|
+ */
|
|
58
|
+ protected function getRedirectionUrl(UserInterface $user)
|
|
59
|
+ {
|
|
60
|
+ return $this->container->get('router')->generate('my_account');
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+?>
|