|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\EventListener; |
|
4
|
|
|
|
|
5
|
|
|
use FOS\UserBundle\Event\FormEvent; |
|
|
|
|
|
|
6
|
|
|
use FOS\UserBundle\Event\GetResponseNullableUserEvent; |
|
|
|
|
|
|
7
|
|
|
use FOS\UserBundle\Event\GetResponseUserEvent; |
|
|
|
|
|
|
8
|
|
|
use FOS\UserBundle\FOSUserEvents; |
|
|
|
|
|
|
9
|
|
|
use stdClass; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
|
|
11
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
|
|
|
|
|
12
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
|
|
13
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class ResettingListener |
|
18
|
|
|
*/ |
|
19
|
|
|
final class ResettingListener implements EventSubscriberInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $container; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var \Symfony\Component\HttpFoundation\RequestStack |
|
28
|
|
|
*/ |
|
29
|
|
|
private $requestStack; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor |
|
33
|
|
|
* |
|
34
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container |
|
35
|
|
|
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(ContainerInterface $container, RequestStack $requestStack) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->container = $container; |
|
40
|
|
|
$this->requestStack = $requestStack; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function getSubscribedEvents() |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
FOSUserEvents::RESETTING_SEND_EMAIL_INITIALIZE => 'onResettingSendEmailInitialize', |
|
50
|
|
|
FOSUserEvents::RESETTING_SEND_EMAIL_COMPLETED => 'onResettingSendEmailCompleted', |
|
51
|
|
|
FOSUserEvents::RESETTING_RESET_INITIALIZE => 'onResettingResetInitialize', |
|
52
|
|
|
FOSUserEvents::RESETTING_RESET_SUCCESS => 'onResettingResetSuccess' |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Return an empty json response if the user does not exist. |
|
58
|
|
|
* |
|
59
|
|
|
* @param \FOS\UserBundle\Event\GetResponseNullableUserEvent $event |
|
60
|
|
|
*/ |
|
61
|
|
|
public function onResettingSendEmailInitialize(GetResponseNullableUserEvent $event) |
|
62
|
|
|
{ |
|
63
|
|
|
$user = $event->getUser(); |
|
64
|
|
|
$ttl = $this->container->getParameter('fos_user.resetting.retry_ttl'); |
|
65
|
|
|
|
|
66
|
|
|
if (null !== $user && !$user->isPasswordRequestNonExpired($ttl)) { |
|
67
|
|
|
return; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$response = new JsonResponse(new stdClass, Response::HTTP_CREATED); |
|
71
|
|
|
$event->setResponse($response); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Return an empty json response once email has been sent. |
|
76
|
|
|
* |
|
77
|
|
|
* @param \FOS\UserBundle\Event\GetResponseUserEvent $event |
|
78
|
|
|
*/ |
|
79
|
|
|
public function onResettingSendEmailCompleted(GetResponseUserEvent $event) |
|
80
|
|
|
{ |
|
81
|
|
|
$response = new JsonResponse(new stdClass, Response::HTTP_CREATED); |
|
82
|
|
|
$event->setResponse($response); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Convert password input to password confirmation input. |
|
87
|
|
|
* |
|
88
|
|
|
* @param \FOS\UserBundle\Event\GetResponseUserEvent $event |
|
89
|
|
|
*/ |
|
90
|
|
|
public function onResettingResetInitialize(GetResponseUserEvent $event) |
|
91
|
|
|
{ |
|
92
|
|
|
$request = $this->requestStack->getCurrentRequest(); |
|
93
|
|
|
$password = $request->request->get('password'); |
|
94
|
|
|
$request->request->set('fos_user_resetting_form', [ |
|
95
|
|
|
'plainPassword' => [ |
|
96
|
|
|
'first' => $password, |
|
97
|
|
|
'second' => $password |
|
98
|
|
|
] |
|
99
|
|
|
]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function onResettingResetSuccess(FormEvent $event) |
|
103
|
|
|
{ |
|
104
|
|
|
$response = new JsonResponse(new stdClass, Response::HTTP_CREATED); |
|
105
|
|
|
$event->setResponse($response); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths