Added a lastLoginAt field to the User entity

This commit is contained in:
Polonkai Gergely 2012-07-07 18:04:15 +02:00
parent 26527d8057
commit adba578db8
5 changed files with 66 additions and 3 deletions

View File

@ -142,4 +142,4 @@ class Role implements RoleInterface
{ {
return $this->name; return $this->name;
} }
} }

View File

@ -307,4 +307,31 @@ class User implements UserInterface, AdvancedUserInterface
{ {
return ($this->accepted_by !== null); return ($this->accepted_by !== null);
} }
} /**
* @var datetime $last_login_at
*/
private $last_login_at;
/**
* Set last_login_at
*
* @param datetime $lastLoginAt
* @return User
*/
public function setLastLoginAt($lastLoginAt)
{
$this->last_login_at = $lastLoginAt;
return $this;
}
/**
* Get last_login_at
*
* @return datetime
*/
public function getLastLoginAt()
{
return $this->last_login_at;
}
}

View File

@ -21,6 +21,10 @@ KekRozsak\FrontBundle\Entity\User:
display_name: display_name:
type: string(50) type: string(50)
nullable: false nullable: false
last_login_at:
type: datetime
nullable: true
default: null
oneToMany: oneToMany:
articles: articles:
targetEntity: Article targetEntity: Article

View File

@ -1,6 +1,10 @@
parameters: parameters:
# kek_rozsak_security.example.class: KekRozsak\SecurityBundle\Example
services: services:
kek_rozsak_security.encoder.crypt: kek_rozsak_security.encoder.crypt:
class: KekRozsak\SecurityBundle\Service\CryptEncoder class: KekRozsak\SecurityBundle\Service\CryptEncoder
security.authentication.success_handler:
class: KekRozsak\SecurityBundle\Security\AuthSuccess
public: false
arguments:
doctrine: @doctrine

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