'/{_locale}/account/password-reset/{token}', 'fr' => '/{_locale}/compte/reinitialisation-mot-de-passe/{token}', ], name: 'security_reset_password')] public function __invoke(Request $request, string $token, string $_route): Response { try { /** @var User $user */ $user = $this->queryBus->query(new ResetPasswordQuery($token)); } catch (HandlerFailedException $e) { /** @var \Exception $exception */ $exception = $e->getPrevious(); if ($exception::class === UserNotFoundException::class) { $this->addFlashWarning('reset_password.user_not_found.exception'); } // token expired, the user must renew its request if ($exception::class === UserLostPasswordTokenExpiredException::class) { $this->addFlashWarning('reset_password.user_lostpassword_token_expired.exception'); } return $this->redirectToRoute('security_lost_password'); } $form = $this->createForm(ResetPasswordFormType::class)->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { /** @var ResetPasswordCommand $resetPasswordCommand */ $resetPasswordCommand = $form->getData(); $resetPasswordCommand->id = $user->getId(); $this->commandBus->dispatch($resetPasswordCommand); $this->addFlashSuccess('reset_password.form.success'); return $this->redirectToRoute('app_login'); } return $this->render('pages/password/reset.html.twig', compact('form')); } }