urlGenerator = $urlGenerator; $this->userStore = $userContainer->getStore(); $this->userBuilder = $userContainer->getBuilder(); $this->formFactory = $formFactory; $this->parameterBag = $parameterBag; } public function supports(Request $request): bool { return $request->isMethod('POST') && $this->getLoginUrl($request) === $request->getPathInfo(); } public function authenticate(Request $request): PassportInterface { $email = trim($request->request->get('email')); $password = $request->request->get('password'); $csrfToken = $request->request->get('_csrf_token'); return new Passport( new UserBadge($email, function ($userIdentifier) { return $this->userStore->getOneByEmail($userIdentifier); }), new PasswordCredentials($password), [ new CsrfTokenBadge('authenticate', $csrfToken), new RememberMeBadge() ] ); } public function onAuthenticationSuccess( Request $request, TokenInterface $token, string $providerKey ): RedirectResponse { $routeName = 'home'; $email = trim($request->request->get('email')); $loginRedirection = $this->parameterBag->get('lc_sov.login_redirection'); $useReferer = $loginRedirection['redirect_referer']; $rolesRedirection = $loginRedirection['roles_redirection']; $user = $this->userStore->getOneByEmail($email); if (isset($useReferer) && $useReferer == true) { $url = $request->request->get('_target_path'); } else { if (!empty($user)) { $roles = $user->getRoles(); foreach ($rolesRedirection as $roleRedirect) { if (in_array($roleRedirect['role'], $roles)) { $routeName = $roleRedirect['redirect']; } } } } $this->userBuilder->setLastLogin($user); if (isset($url) && !empty($url)) { return new RedirectResponse($url); } else { return new RedirectResponse($this->urlGenerator->generate($routeName)); } } protected function getLoginUrl(Request $request): string { return $this->urlGenerator->generate(self::LOGIN_ROUTE); } }