-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use
lexik_jwt_authentication.on_authentication_success
event t…
…o update user last login date
- Loading branch information
1 parent
ae36c59
commit fbe532f
Showing
3 changed files
with
43 additions
and
37 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
43 changes: 43 additions & 0 deletions
43
lib/RoadizCoreBundle/src/EventSubscriber/JwtAuthenticationSuccessEventSubscriber.php
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\EventSubscriber; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent; | ||
use RZ\Roadiz\CoreBundle\Entity\User; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final readonly class JwtAuthenticationSuccessEventSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private ManagerRegistry $managerRegistry, | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
'lexik_jwt_authentication.on_authentication_success' => 'onAuthenticationSuccess', | ||
AuthenticationSuccessEvent::class => 'onAuthenticationSuccess', | ||
]; | ||
} | ||
|
||
public function onAuthenticationSuccess(AuthenticationSuccessEvent $event): void | ||
{ | ||
$user = $event->getUser(); | ||
/* | ||
* Check if user is a passwordless user | ||
*/ | ||
if (!($user instanceof User)) { | ||
return; | ||
} | ||
|
||
$user->setLastLogin(new \DateTime()); | ||
$this->managerRegistry->getManager()->flush(); | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
lib/RoadizCoreBundle/src/Security/Authentication/JwtAuthenticationSuccessHandler.php
This file was deleted.
Oops, something went wrong.