src/UI/Merchant/Controller/ForgotPasswordController.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\UI\Merchant\Controller;
  4. use App\Application\Merchant\Command\SendMerchantForgotPasswordEmail\SendMerchantForgotPasswordEmailCommand;
  5. use App\Infrastructure\Shared\Bus\Command\CommandBusInterface;
  6. use App\UI\Merchant\Form\Type\ForgotPasswordType;
  7. use App\UI\Shared\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. class ForgotPasswordController extends AbstractController
  13. {
  14.     #[Route(path'/forgot-password'name'merchant_forgot_password')]
  15.     public function index(
  16.         Request $request,
  17.         CommandBusInterface $commandBus,
  18.         TranslatorInterface $translator
  19.     ): Response {
  20.         $form $this->createForm(ForgotPasswordType::class, null, [
  21.             'action' => $this->generateUrl('merchant_forgot_password'),
  22.         ]);
  23.         $template 'merchant/forgot_password/index.html.twig';
  24.         $form->handleRequest($request);
  25.         if ($form->isSubmitted()) {
  26.             if (!$form->isValid()) {
  27.                 return $this->createFormErrorsJsonResponse($form);
  28.             }
  29.             $email $form->get('email')->getData();
  30.             $commandBus->dispatch(new SendMerchantForgotPasswordEmailCommand($email));
  31.             return $this->render($template, [
  32.                 'message' => $translator->trans('check_email', ['%email%' => $email]),
  33.             ]);
  34.         }
  35.         return $this->renderForm($template, [
  36.             'form' => $form,
  37.         ]);
  38.     }
  39. }