<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\EventListener;
use ReflectionClass;
use App\Entity\Compteur;
use App\Entity\Utilisateur;
use App\Annotation\ReferencedAttribute;
use Symfony\Component\Security\Core\Security;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Security\Core\User\UserInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
/**
* Listerner for referenced the collection by range.
*
* @author Lee Siong Chan <ahlee2326@me.com>
*/
class AuthenticationSuccessEventListener
{
/**
* @param RequestStack $requestStack
*/
public function __construct(private RequestStack $requestStack, private Security $security)
{
}
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
{
$data = $event->getData();
$user = Utilisateur::cast($event->getUser());
if (!$user instanceof UserInterface) {
return;
}
$data['data'] = array(
'roles' => $user->getRoles(),
'noms' => $user->getNoms(),
'compte' => $user->getCompte()
);
$event->setData($data);
}
}