Added a lastLoginAt field to the User entity
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
parameters:
|
||||
# kek_rozsak_security.example.class: KekRozsak\SecurityBundle\Example
|
||||
|
||||
services:
|
||||
kek_rozsak_security.encoder.crypt:
|
||||
class: KekRozsak\SecurityBundle\Service\CryptEncoder
|
||||
security.authentication.success_handler:
|
||||
class: KekRozsak\SecurityBundle\Security\AuthSuccess
|
||||
public: false
|
||||
arguments:
|
||||
doctrine: @doctrine
|
||||
|
28
src/KekRozsak/SecurityBundle/Security/AuthSuccess.php
Normal file
28
src/KekRozsak/SecurityBundle/Security/AuthSuccess.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace KekRozsak\SecurityBundle\Security;
|
||||
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Bridge\Doctrine\RegistryInterface;
|
||||
|
||||
class AuthSuccess implements AuthenticationSuccessHandlerInterface
|
||||
{
|
||||
private $doctrine;
|
||||
|
||||
public function __construct(RegistryInterface $doctrine)
|
||||
{
|
||||
$this->doctrine = $doctrine;
|
||||
}
|
||||
|
||||
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
|
||||
{
|
||||
$user = $token->getUser();
|
||||
$em = $this->doctrine->getEntityManager();
|
||||
$user->setLastLoginAt(new \DateTime('now'));
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user