Browse Source

Correctif setLastLogin

develop
Fabien Normand 2 years ago
parent
commit
b92411d290
2 changed files with 24 additions and 5 deletions
  1. +16
    -5
      Authenticator/LoginFormAuthenticator.php
  2. +8
    -0
      Builder/User/UserBuilder.php

+ 16
- 5
Authenticator/LoginFormAuthenticator.php View File

@@ -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 View File

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

Loading…
Cancel
Save