Browse Source

Merge branch 'develop'

develop
Guillaume 2 years ago
parent
commit
38a83497f7
3 changed files with 29 additions and 8 deletions
  1. +16
    -5
      Authenticator/LoginFormAuthenticator.php
  2. +8
    -0
      Builder/User/UserBuilder.php
  3. +5
    -3
      EventListener/ExceptionListener.php

+ 16
- 5
Authenticator/LoginFormAuthenticator.php View File



namespace Lc\SovBundle\Authenticator; namespace Lc\SovBundle\Authenticator;


use Lc\SovBundle\Builder\User\UserBuilder;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\User\UserStore; use Lc\SovBundle\Repository\User\UserStore;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;


protected UrlGeneratorInterface $urlGenerator; protected UrlGeneratorInterface $urlGenerator;
protected UserStore $userStore; protected UserStore $userStore;
protected UserBuilder $userBuilder;
protected FormFactoryInterface $formFactory; protected FormFactoryInterface $formFactory;
protected ParameterBagInterface $parameterBag; protected ParameterBagInterface $parameterBag;


public function __construct( public function __construct(
UrlGeneratorInterface $urlGenerator, UrlGeneratorInterface $urlGenerator,
UserStore $userStore,
UserContainer $userContainer,
FormFactoryInterface $formFactory, FormFactoryInterface $formFactory,
ParameterBagInterface $parameterBag ParameterBagInterface $parameterBag
) { ) {
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->userStore = $userStore;
$this->userStore = $userContainer->getStore();
$this->userBuilder = $userContainer->getBuilder();
$this->formFactory = $formFactory; $this->formFactory = $formFactory;
$this->parameterBag = $parameterBag; $this->parameterBag = $parameterBag;
} }


public function authenticate(Request $request): PassportInterface public function authenticate(Request $request): PassportInterface
{ {

$email = trim($request->request->get('email')); $email = trim($request->request->get('email'));
$password = $request->request->get('password'); $password = $request->request->get('password');
$csrfToken = $request->request->get('_csrf_token'); $csrfToken = $request->request->get('_csrf_token');
TokenInterface $token, TokenInterface $token,
string $providerKey string $providerKey
): RedirectResponse { ): RedirectResponse {



$routeName = 'home'; $routeName = 'home';
$email = $request->request->get('email');
$email = trim($request->request->get('email'));
$loginRedirection = $this->parameterBag->get('lc_sov.login_redirection'); $loginRedirection = $this->parameterBag->get('lc_sov.login_redirection');
$useReferer = $loginRedirection['redirect_referer']; $useReferer = $loginRedirection['redirect_referer'];
$rolesRedirection = $loginRedirection['roles_redirection']; $rolesRedirection = $loginRedirection['roles_redirection'];



$user = $this->userStore->getOneByEmail($email);

if (isset($useReferer) && $useReferer == true) { if (isset($useReferer) && $useReferer == true) {
$url = $request->request->get('_target_path'); $url = $request->request->get('_target_path');
} else { } else {
$user = $this->userStore->getOneByEmail($email);

if (!empty($user)) { if (!empty($user)) {
$roles = $user->getRoles(); $roles = $user->getRoles();


} }
} }
} }
$this->userBuilder->setLastLogin($user);


if (isset($url) && !empty($url)) { if (isset($url) && !empty($url)) {
return new RedirectResponse($url); return new RedirectResponse($url);

+ 8
- 0
Builder/User/UserBuilder.php View File

$entity->setUpdatedBy($user); $entity->setUpdatedBy($user);
} }
} }

public function setLastLogin(?UserInterface $user){
if ($user instanceof UserInterface) {
$user->setLastLogin(new \DateTime());
$this->entityManager->update($user);
$this->entityManager->flush();
}
}
} }

+ 5
- 3
EventListener/ExceptionListener.php View File



// On détecte une erreur interne (500), on remove les sessions qui servent de filtre dans l'admin // On détecte une erreur interne (500), on remove les sessions qui servent de filtre dans l'admin
if ($exception instanceof HttpExceptionInterface != true) { if ($exception instanceof HttpExceptionInterface != true) {
foreach ($this->session->all() as $key => $s) {
if (str_contains($key, "_filter")) {
$this->session->remove($key);
if (!headers_sent()) {
foreach ($this->session->all() as $key => $s) {
if (str_contains($key, "_filter")) {
$this->session->remove($key);
}
} }
} }
} }

Loading…
Cancel
Save