|
|
@@ -4,6 +4,7 @@ namespace Lc\SovBundle\Authenticator; |
|
|
|
|
|
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
|
use Lc\SovBundle\Doctrine\EntityManager; |
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
use Symfony\Component\Security\Core\User\UserInterface as SfUserInterface; |
|
|
@@ -30,35 +31,39 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements P |
|
|
|
private $urlGenerator; |
|
|
|
private $csrfTokenManager; |
|
|
|
private $passwordEncoder; |
|
|
|
protected $parameterBag; |
|
|
|
|
|
|
|
public function __construct( |
|
|
|
EntityManager $entityManager, |
|
|
|
UrlGeneratorInterface $urlGenerator, |
|
|
|
CsrfTokenManagerInterface $csrfTokenManager, |
|
|
|
UserPasswordEncoderInterface $passwordEncoder |
|
|
|
) { |
|
|
|
EntityManager $entityManager, |
|
|
|
UrlGeneratorInterface $urlGenerator, |
|
|
|
CsrfTokenManagerInterface $csrfTokenManager, |
|
|
|
UserPasswordEncoderInterface $passwordEncoder, |
|
|
|
ParameterBagInterface $parameterBag |
|
|
|
) |
|
|
|
{ |
|
|
|
$this->entityManager = $entityManager; |
|
|
|
$this->urlGenerator = $urlGenerator; |
|
|
|
$this->csrfTokenManager = $csrfTokenManager; |
|
|
|
$this->passwordEncoder = $passwordEncoder; |
|
|
|
$this->parameterBag = $parameterBag; |
|
|
|
} |
|
|
|
|
|
|
|
public function supports(Request $request) |
|
|
|
{ |
|
|
|
return self::LOGIN_ROUTE === $request->attributes->get('_route') |
|
|
|
&& $request->isMethod('POST'); |
|
|
|
&& $request->isMethod('POST'); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCredentials(Request $request) |
|
|
|
{ |
|
|
|
$credentials = [ |
|
|
|
'email' => $request->request->get('email'), |
|
|
|
'password' => $request->request->get('password'), |
|
|
|
'csrf_token' => $request->request->get('_csrf_token'), |
|
|
|
'email' => $request->request->get('email'), |
|
|
|
'password' => $request->request->get('password'), |
|
|
|
'csrf_token' => $request->request->get('_csrf_token'), |
|
|
|
]; |
|
|
|
$request->getSession()->set( |
|
|
|
Security::LAST_USERNAME, |
|
|
|
$credentials['email'] |
|
|
|
Security::LAST_USERNAME, |
|
|
|
$credentials['email'] |
|
|
|
); |
|
|
|
|
|
|
|
return $credentials; |
|
|
@@ -72,7 +77,7 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements P |
|
|
|
} |
|
|
|
|
|
|
|
$user = $this->entityManager->getRepository(UserInterface::class)->findOneBy( |
|
|
|
['email' => $credentials['email']] |
|
|
|
['email' => $credentials['email']] |
|
|
|
); |
|
|
|
|
|
|
|
if (!$user) { |
|
|
@@ -100,13 +105,32 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements P |
|
|
|
{ |
|
|
|
$routeName = 'home'; |
|
|
|
$email = $request->request->get('email'); |
|
|
|
$user = $this->entityManager->getRepository(UserInterface::class)->findOneBy(['email' => $email]); |
|
|
|
$loginRedirection = $this->parameterBag->get('lc_sov.login_redirection'); |
|
|
|
$useReferer = $loginRedirection['redirect_referer']; |
|
|
|
$rolesRedirection = $loginRedirection['roles_redirection']; |
|
|
|
|
|
|
|
if (isset($useReferer) && $useReferer == true) { |
|
|
|
$url = $request->request->get('_target_path'); |
|
|
|
|
|
|
|
} else { |
|
|
|
$user = $this->entityManager->getRepository(UserInterface::class)->findOneBy(['email' => $email]); |
|
|
|
|
|
|
|
if ($user && ($user->hasRole('ROLE_ADMIN') || $user->hasRole('ROLE_SUPER_ADMIN'))) { |
|
|
|
$routeName = 'admin_dashboard'; |
|
|
|
if (!empty($user)) { |
|
|
|
$roles = $user->getRoles(); |
|
|
|
|
|
|
|
foreach ($rolesRedirection as $roleRedirect) { |
|
|
|
if (array_search($roleRedirect['role'], $roles)) { |
|
|
|
$routeName = $roleRedirect['redirect']; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new RedirectResponse($this->urlGenerator->generate($routeName)); |
|
|
|
if (isset($url) && !empty($url)) { |
|
|
|
return new RedirectResponse($url); |
|
|
|
} else { |
|
|
|
return new RedirectResponse($this->urlGenerator->generate($routeName)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected function getLoginUrl() |