<?php
namespace App\Security\Authenticator;
use Crea\SecurityBundle\Authenticator\FormAuthenticator;
use Crea\SecurityBundle\Helper\RedirectionHelperInterface;
use Crea\SecurityBundle\Voter\UserVoter;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ErpAuthenticator extends FormAuthenticator
{
protected UrlGeneratorInterface $urlGenerator;
public function __construct(UrlGeneratorInterface $urlGenerator,
CsrfTokenManagerInterface $csrfTokenManager,
TranslatorInterface $translator,
EventDispatcherInterface $eventDispatcher,
RedirectionHelperInterface $redirectionHelper,
UserVoter $userVoter,
UserPasswordHasherInterface $passwordHasher)
{
parent::__construct($urlGenerator, $csrfTokenManager, $translator, $eventDispatcher, $redirectionHelper, $userVoter, $passwordHasher);
$this->urlGenerator = $urlGenerator;
}
/**
* This will be called on every request and your job is to decide if the authenticator should be used for this
* request (return true) or if it should be skipped (return false).
* @inheritDoc
*/
public function supports(Request $request): bool
{
return 'app_login' === $request->attributes->get('_route') && $request->isMethod('POST');
}
/**
* @inheritDoc
*/
protected function getLoginUrl(): string
{
return $this->urlGenerator->generate('app_login');
}
}