diff --git a/src/KekRozsak/FrontBundle/Entity/Role.php b/src/KekRozsak/FrontBundle/Entity/Role.php index 12e4a47..a988273 100644 --- a/src/KekRozsak/FrontBundle/Entity/Role.php +++ b/src/KekRozsak/FrontBundle/Entity/Role.php @@ -142,4 +142,4 @@ class Role implements RoleInterface { return $this->name; } -} +} \ No newline at end of file diff --git a/src/KekRozsak/FrontBundle/Entity/User.php b/src/KekRozsak/FrontBundle/Entity/User.php index aff4a20..0b60ad1 100644 --- a/src/KekRozsak/FrontBundle/Entity/User.php +++ b/src/KekRozsak/FrontBundle/Entity/User.php @@ -307,4 +307,31 @@ class User implements UserInterface, AdvancedUserInterface { 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; + } +} \ No newline at end of file diff --git a/src/KekRozsak/FrontBundle/Resources/config/doctrine/User.orm.yml b/src/KekRozsak/FrontBundle/Resources/config/doctrine/User.orm.yml index ee0ed90..ac18718 100644 --- a/src/KekRozsak/FrontBundle/Resources/config/doctrine/User.orm.yml +++ b/src/KekRozsak/FrontBundle/Resources/config/doctrine/User.orm.yml @@ -21,6 +21,10 @@ KekRozsak\FrontBundle\Entity\User: display_name: type: string(50) nullable: false + last_login_at: + type: datetime + nullable: true + default: null oneToMany: articles: targetEntity: Article diff --git a/src/KekRozsak/SecurityBundle/Resources/config/services.yml b/src/KekRozsak/SecurityBundle/Resources/config/services.yml index bf3655d..ebf27d9 100644 --- a/src/KekRozsak/SecurityBundle/Resources/config/services.yml +++ b/src/KekRozsak/SecurityBundle/Resources/config/services.yml @@ -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 diff --git a/src/KekRozsak/SecurityBundle/Security/AuthSuccess.php b/src/KekRozsak/SecurityBundle/Security/AuthSuccess.php new file mode 100644 index 0000000..d69be21 --- /dev/null +++ b/src/KekRozsak/SecurityBundle/Security/AuthSuccess.php @@ -0,0 +1,28 @@ +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(); + } +} +