<?php
namespace App\EventListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
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)
{
$request = $this->requestStack->getCurrentRequest();
$payload = $event->getData();
if($user = $event->getUser()){
$payload['id'] = $user->getId();
$payload['civility'] = $user->getCivility();
$payload['firstname'] = $user->getFirstname();
$payload['lastname'] = $user->getLastname();
$payload['birthdate'] = $user->getBirthdate();
$payload['email'] = $user->getEmail();
$payload['phone'] = $user->getPhone();
$payload['mobile'] = $user->getMobile();
$payload['enabled'] = $user->isEnabled();
$payload['image'] = $user->getImage()?$user->getImage()->getPath().$user->getImage()->getName().'.'.$user->getImage()->getExtension():null;
}
$event->setData($payload);
}
}