<?php
namespace ProtectoBundle\EventListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Pimcore\Model\DataObject\User;
use Symfony\Component\HttpFoundation\RequestStack;
class JWTCreatedListener
{
/**
* @var RequestStack
*/
private $requestStack;
/**
* @param RequestStack $requestStack
*/
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
/**
* @param JWTCreatedEvent $event
*
* @return void
*/
public function onJWTCreated(JWTCreatedEvent $event)
{
/**
* @var User $user
*/
$request = $this->requestStack->getCurrentRequest();
$payload = $event->getData();
$payload['ip'] = $request->getClientIp();
$user = $event->getUser();
if ($user instanceof User) {
$payload['id'] = $user->getId();
$payload['roles']['canDownloadProductImages'] = $user->getCanDownloadProductImages();
$payload['roles']['canDownloadProductDocuments'] = $user->getCanDownloadProductDocuments();
}
$event->setData($payload);
}
}