bundles/ProtectoBundle/EventListener/JWTCreatedListener.php line 29

Open in your IDE?
  1. <?php
  2. namespace ProtectoBundle\EventListener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
  4. use Pimcore\Model\DataObject\User;
  5. use Symfony\Component\HttpFoundation\RequestStack;
  6. class JWTCreatedListener
  7. {
  8.     /**
  9.      * @var RequestStack
  10.      */
  11.     private $requestStack;
  12.     /**
  13.      * @param RequestStack $requestStack
  14.      */
  15.     public function __construct(RequestStack $requestStack)
  16.     {
  17.         $this->requestStack $requestStack;
  18.     }
  19.     /**
  20.      * @param JWTCreatedEvent $event
  21.      *
  22.      * @return void
  23.      */
  24.     public function onJWTCreated(JWTCreatedEvent $event)
  25.     {
  26.         /**
  27.          * @var User $user
  28.          */
  29.         $request $this->requestStack->getCurrentRequest();
  30.         $payload $event->getData();
  31.         $payload['ip'] = $request->getClientIp();
  32.         $user $event->getUser();
  33.         if ($user instanceof User) {
  34.             $payload['id'] = $user->getId();
  35.             $payload['roles']['canDownloadProductImages'] = $user->getCanDownloadProductImages();
  36.             $payload['roles']['canDownloadProductDocuments'] = $user->getCanDownloadProductDocuments();
  37.         }
  38.         $event->setData($payload);
  39.     }
  40. }