Gergely POLONKAI fab08cad6f Refactored code to comply with PSR-*
Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
2012-08-16 15:52:41 +02:00

38 lines
1.1 KiB
PHP

<?php
namespace KekRozsak\SecurityBundle\Security;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Security\Core\Event\AuthenticationEvent;
class AuthSuccess implements AuthenticationSuccessHandlerInterface
{
private $doctrine;
public function __construct(RegistryInterface $doctrine)
{
$this->doctrine = $doctrine;
}
public function onSecurityAuthenticationSuccess(AuthenticationEvent $event)
{
$user = $event->getAuthenticationToken()->getUser();
$em = $this->doctrine->getEntityManager();
$user->setLastLoginAt(new \DateTime('now'));
$em->persist($user);
$em->flush();
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
$user = $token->getUser();
$em = $this->doctrine->getEntityManager();
$user->setLastLoginAt(new \DateTime('now'));
$em->persist($user);
$em->flush();
}
}