src/Security/Authenticator/ErpAuthenticator.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Security\Authenticator;
  3. use Crea\SecurityBundle\Authenticator\FormAuthenticator;
  4. use Crea\SecurityBundle\Helper\RedirectionHelperInterface;
  5. use Crea\SecurityBundle\Voter\UserVoter;
  6. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  9. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  10. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. class ErpAuthenticator extends FormAuthenticator
  13. {
  14.     protected UrlGeneratorInterface $urlGenerator;
  15.     public function __construct(UrlGeneratorInterface       $urlGenerator,
  16.                                 CsrfTokenManagerInterface   $csrfTokenManager,
  17.                                 TranslatorInterface         $translator,
  18.                                 EventDispatcherInterface    $eventDispatcher,
  19.                                 RedirectionHelperInterface  $redirectionHelper,
  20.                                 UserVoter                   $userVoter,
  21.                                 UserPasswordHasherInterface $passwordHasher)
  22.     {
  23.         parent::__construct($urlGenerator$csrfTokenManager$translator$eventDispatcher$redirectionHelper$userVoter$passwordHasher);
  24.         $this->urlGenerator $urlGenerator;
  25.     }
  26.     /**
  27.      * This will be called on every request and your job is to decide if the authenticator should be used for this
  28.      * request (return true) or if it should be skipped (return false).
  29.      * @inheritDoc
  30.      */
  31.     public function supports(Request $request): bool
  32.     {
  33.         return 'app_login' === $request->attributes->get('_route') && $request->isMethod('POST');
  34.     }
  35.     /**
  36.      * @inheritDoc
  37.      */
  38.     protected function getLoginUrl(): string
  39.     {
  40.         return $this->urlGenerator->generate('app_login');
  41.     }
  42. }