src/EventListener/JWTCreatedListener.php line 19
<?php
declare(strict_types=1);
namespace App\EventListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Symfony\Component\HttpFoundation\RequestStack;
class JWTCreatedListener
{
private RequestStack $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function onJWTCreated(JWTCreatedEvent $event): void
{
$request = $this->requestStack->getCurrentRequest();
$payload = $event->getData();
$query = json_decode($request->getContent(), true);
$user = $event->getUser();
$payload['ip'] = $request->getClientIp();
$payload['id_user'] = $user->getId();
$payload['firstName'] = $user->getFirstName();
$payload['lastName'] = $user->getLastName();
$payload['password'] = $query['password'];
$payload['hashed_pws_db'] = $user->getPassword();
$payload['hashed_pws'] = $user->getPassword();
/*
$payload['fingerprint'] = $query['fingerprint'];
$payload['build_version'] = $query['build_version'];
$payload['version_name'] = $query['version_name'];
$payload['MacWlanAddress'] = $query['MacWlanAddress'];
$payload['MacEthAddress'] = $query['MacEthAddress'];
$payload['ipAddressV4'] = $query['ipAddressV4'];
$payload['ipAddressV6'] = $query['ipAddressV6'];
$payload['latitude_user'] = $query['latitude_user'];
$payload['longitude_user'] = $query['longitude_user'];
$payload['imei'] = $query['imei'];
$payload['id_support'] = $query['id_support'];*/
$event->setData($payload);
$header = $event->getHeader();
$header['cty'] = 'JWT';
$event->setHeader($header);
}
}