src/EventSubscriber/CoreEventsSubscriber.php line 86

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Controller\SecurePageInterface;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Empire\Core\Core;
  6. use Exception;
  7. use Psr\Log\LoggerInterface;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. use Symfony\Component\Routing\RequestContext;
  16. use Twig\Environment;
  17. class CoreEventsSubscriber implements EventSubscriberInterface
  18. {
  19.     private $request;
  20.     private $session;
  21.     private $requestStack;
  22.     private $resolver;
  23.     private $logger;
  24.     public function __construct (
  25.             EntityManagerInterface $entityManager,
  26.             RequestStack $request,
  27.             RequestContext $rc,
  28.             Environment $twig,
  29.             RequestStack $requestStack,
  30.             LoggerInterface $logger
  31.             //ControllerResolver $resolver
  32.     ) {
  33.         Core::setDB($entityManager->getConnection());
  34.         //$this->connection = $entityManager->getConnection();
  35.         Core::set('version''8.4.3' trim(file_exists(EMPIRE_WEBROOT '/VERSION') ? '-'file_get_contents(EMPIRE_WEBROOT '/VERSION') : ''));
  36.         $base_url $rc->getScheme() . "://" $rc->getHost() . "/" $rc->getBaseUrl();
  37.         $this->request $request->getCurrentRequest();
  38.         Core::set('base_url'$base_url);
  39.         $this->requestStack $requestStack;
  40.         $this->session $this->requestStack->getSession();
  41.         Core::setSession($this->session);
  42.         Core::setTwig($twig);
  43.         //$this->resolver = $resolver;
  44.         $this->logger $logger;
  45.         Core::set('discord.guild'"503020279136649250");
  46.         Core::set('discord.token'"NTAzMTc1OTE5MDA4MjE5MTQ2.DqyrLQ.d4W-wNoNGUORjnudyx0bdmJkle8");
  47.         Core::set('discord.clientid'"503175919008219146");
  48.         Core::set('discord.clientse'"0coE9mZSGpOXkPZkiL5rOOwDL4WcfTZN");
  49.         Core::set('discord.botname'"Bot"); // Name of the ROLE in discord server
  50.         Core::set('discord.postINB'true); // Keep disabled for now
  51.         Core::set('discord.dev.inb.webhookUrl'"https://discord.com/api/webhooks/1086305402221772951/shyH8ajqj7PnDrV3cWiLK3zorihe-rmVyPc14UZL2RZCRpuhUnR15S5qPHZ-UIdtsCne");
  52.         Core::set('discord.dev.inb.avatarUrl''https://swc-empire.com/assets/uploads/image_26_MmM3ZGM0M2_empire-logo-large.png');
  53.         Core::set('discord.dev.inb.username''DEV Imperial News Bureau');
  54.         Core::set('discord.membersLinkEnabled'false); // If set to false: Individual Overwrite via Access-Key 'Discord-Release'
  55.         Core::set('discord.imperialRole'"887246214549090365");
  56.         Core::set('discord.tier1'"888688878431662110");
  57.         Core::set('discord.tier2'"888688794621083669");
  58.         Core::set('discord.tier3'"888688698424696883");
  59.         Core::set('discord.tier4'"888688420463980605");
  60.         
  61.         Core::set('combine.dev.clientid'"65b86ccb18fe01e20e39f10236574a5ae5c56127");
  62.         Core::set('combine.dev.clientse'"77a8cda2e4e0218a4c116a6c0c11fda7b7646e35");
  63.         Core::set('combine.prod.clientid'"4d2974503f6f59966386378879b18467734ff054");
  64.         Core::set('combine.prod.clientse'"94895db6fb9ee1846a3242118d1217e0ae84b5be");
  65.     }
  66.     /**
  67.      * @inheritDoc
  68.      * @return Array
  69.      */
  70.     public static function getSubscribedEvents()
  71.     {
  72.         return [
  73.             KernelEvents::CONTROLLER =>  [['pathInfo'50],['loginSetup'99], ['loginCheck'0]]
  74.         ];
  75.     }
  76.     public function pathInfo(ControllerEvent $event) {
  77.         Core::set('fullPage'explode("~",$this->request->getPathInfo())[0]);
  78.         Core::set('secure'false);
  79.     }
  80.     public function loginSetup(ControllerEvent $event) {
  81.         $request $this->request;
  82.         $this->logger->info('irms_token: ' $request->cookies->get('irms_token') );
  83.         $this->logger->info('member_id: ' $this->session->get('irms_token') );
  84.         if($request->cookies->get('irms_token') && !$this->session->get('member_id')) {
  85.             try {
  86.                 \Empire\Core\Login::cookieLogin($request->cookies->get('irms_token'));
  87.             } catch (Exception $ex) {
  88.                 $this->session->getFlashBag()->add('error''While attempting to remember your login, the following error occurred: ' $ex->getMessage());
  89.             }
  90.         }
  91.         if($request->request->get('login')) {
  92.             try {
  93.                 $getLogin = \Empire\Core\Login::processLogin($request);
  94.             } catch (Exception $ex) {
  95.                 $getLogin false;
  96.                 $this->session->getFlashBag()->add('error''While attempting to login, the following error occured: ' $ex->getMessage());
  97.             }
  98.             if ($getLogin) {
  99.                 if($request->request->get('rememberMe'false)) {
  100.                     try {
  101.                         \Empire\Core\Login::setLoginCookie();
  102.                     } catch (Exception $e) {
  103.                         $this->session->getFlashBag()->add('error'$e->getMessage());
  104.                     }
  105.                 }
  106.             } else {
  107.                 $this->session->getFlashBag()->add('error''Unable to log you in.');
  108.             }
  109.         }
  110.         Core::setUser(\Empire\Core\Login::getLoggedIn());
  111.         $redirectUrl $request->request->get('redirectUrl');
  112.         if ($redirectUrl != null ) {
  113.             $event->setController(function() use ($redirectUrl) {
  114.                 return new RedirectResponse(urldecode($redirectUrl));
  115.             });
  116.         }
  117.         $referer $request->headers->get('referer');
  118.         if (!is_null($referer)) {
  119.             return new RedirectResponse($referer);
  120.         }
  121.     }
  122.     public function loginCheck(ControllerEvent $event) {
  123.         $controller $event->getController();
  124.         if(is_array($controller)) $controller $controller[0];
  125.         if($controller instanceof SecurePageInterface) {
  126.             $resp Core::loginCheck();
  127.             if($resp instanceof Response) {
  128.                 $event->setController(function () use ($resp) {
  129.                    return $resp;
  130.                 });
  131.             }
  132.             Core::set('secure'true);
  133.         }
  134.     }
  135. }