parent
6c6efebd6a
commit
cd057a6b65
@ -0,0 +1 @@ |
||||
export const ENTRYPOINT = process.env.APP_API_PLATFORM_URL; |
||||
@ -0,0 +1,41 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\EventListener; |
||||
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent; |
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
||||
use Symfony\Component\Security\Core\User\UserInterface; |
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder; |
||||
use Symfony\Component\Serializer\SerializerInterface; |
||||
use Twig\Environment; |
||||
|
||||
class TwigListener |
||||
{ |
||||
private $twig; |
||||
public function __construct(Environment $twig, SerializerInterface $serializer, TokenStorageInterface $tokenStorage) |
||||
{ |
||||
$this->twig = $twig; |
||||
$this->tokenStorage = $tokenStorage; |
||||
$this->serializer = $serializer; |
||||
} |
||||
|
||||
public function __invoke(RequestEvent $event): void |
||||
{ |
||||
$request = $event->getRequest(); |
||||
$user = $this->tokenStorage->getToken()->getUser(); |
||||
$data = null; |
||||
$isAuth = false; |
||||
if ($user instanceof UserInterface) { |
||||
$userClone = clone $user; |
||||
$userClone->setPassword(''); |
||||
$data = $this->serializer->serialize($userClone, JsonEncoder::FORMAT); |
||||
$isAuth = true; |
||||
} |
||||
|
||||
$this->twig->addGlobal('from_vue', $request->request->get('from_vue') ? 1 : 0); |
||||
$this->twig->addGlobal('is_authenticated', json_encode($isAuth)); |
||||
$this->twig->addGlobal('user', $data ?? json_encode($data)); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue