Przeglądaj źródła

Merge branch 'develop'

develop
Fabien Normand 2 lat temu
rodzic
commit
1e6d693281
3 zmienionych plików z 29 dodań i 8 usunięć
  1. +16
    -5
      Authenticator/LoginFormAuthenticator.php
  2. +8
    -0
      Builder/User/UserBuilder.php
  3. +5
    -3
      EventListener/ExceptionListener.php

+ 16
- 5
Authenticator/LoginFormAuthenticator.php Wyświetl plik

@@ -2,6 +2,9 @@

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 Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormFactoryInterface;
@@ -28,17 +31,19 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator

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

public function __construct(
UrlGeneratorInterface $urlGenerator,
UserStore $userStore,
UserContainer $userContainer,
FormFactoryInterface $formFactory,
ParameterBagInterface $parameterBag
) {
$this->urlGenerator = $urlGenerator;
$this->userStore = $userStore;
$this->userStore = $userContainer->getStore();
$this->userBuilder = $userContainer->getBuilder();
$this->formFactory = $formFactory;
$this->parameterBag = $parameterBag;
}
@@ -50,6 +55,7 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator

public function authenticate(Request $request): PassportInterface
{

$email = trim($request->request->get('email'));
$password = $request->request->get('password');
$csrfToken = $request->request->get('_csrf_token');
@@ -71,17 +77,21 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator
TokenInterface $token,
string $providerKey
): RedirectResponse {



$routeName = 'home';
$email = $request->request->get('email');
$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 {
$user = $this->userStore->getOneByEmail($email);

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

@@ -92,6 +102,7 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator
}
}
}
$this->userBuilder->setLastLogin($user);

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

+ 8
- 0
Builder/User/UserBuilder.php Wyświetl plik

@@ -83,4 +83,12 @@ class UserBuilder
$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 Wyświetl plik

@@ -22,9 +22,11 @@ class ExceptionListener

// On détecte une erreur interne (500), on remove les sessions qui servent de filtre dans l'admin
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);
}
}
}
}

Ładowanie…
Anuluj
Zapisz