src/Core/Action/Http/ForgottenPasswordAction.php line 33
<?phpdeclare(strict_types=1);/*** Copyright (c) 2020 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2020 TECLA Consulting Group oü*/namespace App\Core\Action\Http;use App\Core\Event\UserPasswordResetRequestEvent;use App\Core\Form\Type\ForgottenPasswordRequestFormType;use App\Core\Query\User\FindOneByIdentifierQueryInterface;use Symfony\Component\EventDispatcher\EventDispatcherInterface;use Symfony\Component\Form\FormFactoryInterface;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\RouterInterface;use Twig\Environment;final class ForgottenPasswordAction{private FormFactoryInterface $formFactory;private FindOneByIdentifierQueryInterface $findUserQuery;private EventDispatcherInterface $eventDispatcher;private RequestStack $requestStack;private RouterInterface $router;private Environment $twig;public function __construct(FormFactoryInterface $formFactory,FindOneByIdentifierQueryInterface $findUserQuery,EventDispatcherInterface $eventDispatcher,RequestStack $requestStack,RouterInterface $router,Environment $twig) {$this->formFactory = $formFactory;$this->findUserQuery = $findUserQuery;$this->eventDispatcher = $eventDispatcher;$this->requestStack = $requestStack;$this->router = $router;$this->twig = $twig;}public function __invoke(Request $request): Response{$form = $this->formFactory->create(ForgottenPasswordRequestFormType::class);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$data = $form->getData();if (null !== $user = $this->findUserQuery->execute($data['username'])) {$event = new UserPasswordResetRequestEvent($user);$this->eventDispatcher->dispatch($event);}$this->requestStack->getSession()->set('app_forgotten_password.email', $data['username']);return new RedirectResponse($this->router->generate('app.core.http.forgotten_password.email_sent'));}return new Response($this->twig->render('packages/core/action/http/forgotten_password.html.twig', ['form' => $form->createView(),]));}}