src/Listener/JWTAuthenticatedListener.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Listener;
  3. use App\Entity\User;
  4. use App\Repository\UserRepository;
  5. use App\Services\SqlService\SqlService;
  6. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTAuthenticatedEvent;
  7. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. class JWTAuthenticatedListener
  10. {
  11.     private $requestStack;
  12.     private $userRepository;
  13.     private SqlService $sqlService;
  14.     /**
  15.      * @param RequestStack $requestStack
  16.      * @param UserRepository $userRepository
  17.      * se ejecuta el tercero
  18.      */
  19.     public function __construct(RequestStack $requestStackUserRepository $userRepositorySqlService $sqlService)
  20.     {
  21.         $this->requestStack $requestStack;
  22.         $this->userRepository $userRepository;
  23.         $this->sqlService $sqlService;
  24.     }
  25.     public function onJWTAuthenticated(JWTAuthenticatedEvent $event)
  26.     {
  27.         $payload $event->getPayload();
  28.         $time time();
  29.         $sql "UPDATE session SET last_connection = $time WHERE user_id =  ".$payload['uuid']."  ";
  30.         $this->sqlService->update($sql);
  31.     }
  32. }