<?php
namespace App\EventListener;
use Imperium\Config\iConfig;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Imperium\StaticUtils\Utils;
class RouteListener implements EventSubscriberInterface
{
// use ControllerTrait;
private $request;
private $authManager;
private $router;
private $blockManager;
private $tokenStorage;
protected $session;
protected $IdCompte;
protected $PD_IdDataBase;
protected $PD_IdDiffList;
protected $OTP;
protected $CryptSecretKey;
public function __construct(TokenStorageInterface $tokenStorage,SessionInterface $session, RequestStack $requestStack,RouterInterface $router)
{
$this->request = $requestStack->getCurrentRequest();
$this->router = $router;
$this->tokenStorage = $tokenStorage;
$this->session = $session;
$this->OTP = $session->get('otp');
$this->CryptSecretKey = iConfig::getCryptSecretKey();
}
public function onRouteRequest($event){
try {
$salt = $this->request->get('salt',null);
$ciphertext = $this->request->get('ciphertext',null);
$iv = $this->request->get('iv',null);
if($salt && $ciphertext && $iv && $this->OTP){
$data = Utils::dataDecryptJWT(["salt" =>$salt,"ciphertext"=>$ciphertext,"iv"=>$iv ],$this->OTP);
$data = json_decode(json_encode($data),true);
foreach ($data as $key => $dataValue) {
$this->request->request->set($key,$dataValue);
}
}
} catch (\Exception $e) {
throw $e;
}
}
public static function getSubscribedEvents(){
return array(
KernelEvents::REQUEST => 'onRouteRequest'
);
}
}