<?php
namespace App\Listener;
use App\Entity\User;
use App\Repository\UserRepository;
use App\Services\SqlService\SqlService;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTAuthenticatedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent;
use Symfony\Component\HttpFoundation\RequestStack;
class JWTAuthenticatedListener
{
private $requestStack;
private $userRepository;
private SqlService $sqlService;
/**
* @param RequestStack $requestStack
* @param UserRepository $userRepository
* se ejecuta el tercero
*/
public function __construct(RequestStack $requestStack, UserRepository $userRepository, SqlService $sqlService)
{
$this->requestStack = $requestStack;
$this->userRepository = $userRepository;
$this->sqlService = $sqlService;
}
public function onJWTAuthenticated(JWTAuthenticatedEvent $event)
{
$payload = $event->getPayload();
$time = time();
$sql = "UPDATE session SET last_connection = $time WHERE user_id = ".$payload['uuid']." ";
$this->sqlService->update($sql);
}
}