This repository has been archived by the owner on Sep 23, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interactive_login listener to update User.lastLogin
- Loading branch information
Showing
4 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
|
|||
<container xmlns="http://www.symfony-project.org/schema/dic/services" | |||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd"> | |||
|
|||
<parameters> | |||
<parameter key="fos_user.security.interactive_login_listener.class">FOS\UserBundle\Security\InteractiveLoginListener</parameter> | |||
</parameters> | |||
|
|||
<services> | |||
<service id="fos_user.security.interactive_login_listener" class="%fos_user.security.interactive_login_listener.class%"> | |||
<argument type="service" id="fos_user.user_manager" /> | |||
</service> | |||
</services> | |||
|
|||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
<?php | |||
|
|||
namespace FOS\UserBundle\Security; | |||
|
|||
use FOS\UserBundle\Model\UserManagerInterface; | |||
use FOS\UserBundle\Model\User; | |||
use Symfony\Component\Security\Http\Firewall\ListenerInterface; | |||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | |||
use Symfony\Component\EventDispatcher\Event; | |||
use DateTime; | |||
|
|||
class InteractiveLoginListener implements ListenerInterface | |||
{ | |||
protected $userManager; | |||
|
|||
public function __construct(UserManagerInterface $userManager) | |||
{ | |||
$this->userManager = $userManager; | |||
} | |||
|
|||
public function register(EventDispatcherInterface $dispatcher) | |||
{ | |||
$dispatcher->connect('security.interactive_login', array($this, 'listenToInteractiveLogin')); | |||
} | |||
|
|||
public function unregister(EventDispatcherInterface $dispatcher) | |||
{ | |||
} | |||
|
|||
public function listenToInteractiveLogin(Event $event) | |||
{ | |||
$user = $event->get('token')->getUser(); | |||
|
|||
if ($user instanceof User) { | |||
$user->setLastLogin(new DateTime()); | |||
$this->userManager->updateUser($user); | |||
} | |||
} | |||
} |