Bladeren bron

Merge branch 'develop'

develop
Guillaume 2 jaren geleden
bovenliggende
commit
38a83497f7
3 gewijzigde bestanden met toevoegingen van 29 en 8 verwijderingen
  1. +16
    -5
      Authenticator/LoginFormAuthenticator.php
  2. +8
    -0
      Builder/User/UserBuilder.php
  3. +5
    -3
      EventListener/ExceptionListener.php

+ 16
- 5
Authenticator/LoginFormAuthenticator.php Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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);
}
}
}
}

Laden…
Annuleren
Opslaan