src/Security/LoginAuthenticator.php line 20
<?phpnamespace App\Security;use App\Service\PasswordService;use Symfony\Component\HttpFoundation\Request;use Symfony\Bundle\SecurityBundle\Security;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\RouterInterface;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\Security\Http\Util\TargetPathTrait;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Component\Security\Http\Authenticator\Passport\Passport;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;class LoginAuthenticator extends AbstractLoginFormAuthenticator{use TargetPathTrait;public const LOGIN_ROUTE = 'app_home';private $router;private PasswordService $passwordService;public function __construct(private UrlGeneratorInterface $urlGenerator, RouterInterface $router, PasswordService $passwordService){$this->router = $router;$this->passwordService = $passwordService;}public function authenticate(Request $request): Passport{$email = $request->request->get('email', '');$request->getSession()->set(Security::LAST_USERNAME, $email);return new Passport(new UserBadge($email),new PasswordCredentials($request->request->get('password', '')),[new CsrfTokenBadge('authenticate', $request->request->get('_csrf_token')),]);}public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response{$case = $this->passwordService->checkCasePassword($token->getUser());if ($case != 'none') {return new RedirectResponse($this->urlGenerator->generate('app_edit_password', ["case" => $case]));} else {$roles = $token->getUser()->getRoles();$user = $token->getUser();if (in_array('ROLE_COMPANY', $roles, true)) {$company = $user->getCompanyMember()->getCompany();if (count($company->getCompanyQuestionnaires()) > 0) {$redirection = new RedirectResponse($this->router->generate('app_roadmap_index'));} else if ($company->getCompanyLabelNR()) {$redirection = new RedirectResponse($this->router->generate('app_label_nr'));}} elseif (in_array('ROLE_ADMIN', $roles, true) || in_array('ROLE_BILBEA', $roles, true)) {$redirection = new RedirectResponse($this->router->generate('app_backoffice'));}return $redirection;// return new RedirectResponse($this->urlGenerator->generate('app_home'));}}protected function getLoginUrl(Request $request): string{return $this->urlGenerator->generate(self::LOGIN_ROUTE);}}