src/Controller/DefaultController.php line 101

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Business\ContactUs;
  4. use App\Entity\UserPreference;
  5. use App\Extern\NeosService;
  6. use App\Extern\XrmService;
  7. use App\Form\ContactUsType;
  8. use App\Services\ApplicationRoleService;
  9. use App\Services\DashboardService;
  10. use App\Services\Elastic\ElasticNeosService;
  11. use App\Services\NewslettersService;
  12. use App\Services\NotificationSenderHelperService;
  13. use App\Services\S3Provider;
  14. use App\Services\WebserviceService;
  15. use GuzzleHttp\Client;
  16. use JSend\JSendResponse;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  19. use Symfony\Component\HttpFoundation\JsonResponse;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  23. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  24. use Symfony\Component\Security\Core\Security as SecurityInterface;
  25. class DefaultController extends BaseController
  26. {
  27.     /** @var S3Provider $s3Provider */
  28.     protected $s3Provider;
  29.     /** @var ElasticNeosService $elasticNeosService */
  30.     protected $elasticNeosService;
  31.     /** @var ApplicationRoleService $accessRightsService */
  32.     protected $accessRightsService;
  33.     /** @var NeosService $neosService */
  34.     protected $neosService;
  35.     /** @var NotificationSenderHelperService $notificationSenderHelperService */
  36.     protected $notificationSenderHelperService;
  37.     /**
  38.      * @var WebserviceService $webserviceService
  39.      */
  40.     protected $webserviceService;
  41.     /** @var NewslettersService $newslettersService */
  42.     private $newslettersService;
  43.     /** @var DashboardService $dashboardService */
  44.     private $dashboardService;
  45.     private $xrmService;
  46.     /**
  47.      * DefaultController constructor.
  48.      *
  49.      * @param S3Provider $s3Provider
  50.      * @param ElasticNeosService $elasticNeosService
  51.      * @param ApplicationRoleService $accessRightsService
  52.      * @param NeosService $neosService
  53.      * @param NotificationSenderHelperService $notificationSenderHelperService
  54.      * @param SecurityInterface $security
  55.      * @param NewslettersService $newslettersService
  56.      * @param DashboardService $dashboardService
  57.      * @param WebserviceService $webserviceService
  58.      * @param XrmService $xrmService
  59.      */
  60.     public function __construct(
  61.         S3Provider                      $s3Provider,
  62.         ElasticNeosService              $elasticNeosService,
  63.         ApplicationRoleService          $accessRightsService,
  64.         NeosService                     $neosService,
  65.         NewslettersService              $newslettersService,
  66.         NotificationSenderHelperService $notificationSenderHelperService,
  67.         SecurityInterface               $security,
  68.         DashboardService                $dashboardService,
  69.         WebserviceService               $webserviceService,
  70.         XrmService                      $xrmService
  71.     )
  72.     {
  73.         parent::__construct($security);
  74.         $this->s3Provider $s3Provider;
  75.         $this->newslettersService $newslettersService;
  76.         $this->elasticNeosService $elasticNeosService;
  77.         $this->accessRightsService $accessRightsService;
  78.         $this->neosService $neosService;
  79.         $this->notificationSenderHelperService $notificationSenderHelperService;
  80.         $this->dashboardService $dashboardService;
  81.         $this->webserviceService $webserviceService;
  82.         $this->xrmService $xrmService;
  83.     }
  84.     /**
  85.      * expose = true to be accessible forom javascript.
  86.      * @Route("/", name="homepage", options={"expose" = true})
  87.      *
  88.      * @return Response
  89.      */
  90.     public function indexAction()
  91.     {
  92.         $isRegistered false;
  93.         if ($this->getUser() != null) {
  94.             $isRegistered $this->newslettersService->isLoggedInUserRegisteredToInsights($this->getUser()->getUid());
  95.         }
  96.         $adminUrl null;
  97.         return $this->render('default/homepage.html.twig', [
  98.             'isRegistered' => $isRegistered,
  99.             BaseController::PARAM_ADMIN_URL => $adminUrl
  100.         ]);
  101.     }
  102.     /**
  103.      * Temporary access to the homepage for admin
  104.      * @Route("/homepage", name="homepage_intern")
  105.      *
  106.      * @return Response
  107.      */
  108.     public function internAction()
  109.     {
  110.         return $this->indexAction();
  111.     }
  112.     /**
  113.      * Auth check
  114.      *
  115.      * @Route("/auth/check", name="eurovision_security_login_check", methods={"GET"})
  116.      */
  117.     public function authCheckAction(Request $request)
  118.     {
  119.         return $this->indexAction();
  120.     }
  121.     /**
  122.      * @Route("/not-authorized", name="eurovision_not_authorized")
  123.      */
  124.     public function notAuthorizedAction(Request $request)
  125.     {
  126.         $message $request->get("message");
  127.         if ($message === null) {
  128.             $message "";
  129.         }
  130.         return $this->render(
  131.             'default/index-notAuthorized.html.twig',
  132.             ['username' => $this->getUser(), "message" => $message]
  133.         );
  134.     }
  135.     /**
  136.      * @Route("/no-booking-authorized", name="eurovision_no_booking_authorized")
  137.      */
  138.     public function notAuthorizedToBookAction(Request $request)
  139.     {
  140.         $message $request->get("message");
  141.         if ($message === null) {
  142.             $message "";
  143.         }
  144.         $parts explode('@'$this->getUser()->getEmail());
  145.         $domain array_pop($parts);
  146.         $organization $this->xrmService->getOrganizationsRelatedToSpecificEmailDomain($domain);
  147.         return $this->render(
  148.             'default/index-no-booking-authorized.html.twig',
  149.             ['username' => $this->getUser(), "organizationMappingPossible" => count($organization) > 0"message" => $message]
  150.         );
  151.     }
  152.     /**
  153.      * @Route("/no-booking-authorized-company-inactive", name="eurovision_no_booking_authorized_company_inactive")
  154.      */
  155.     public function notAuthorizedToBookCompanyInactiveAction(Request $request)
  156.     {
  157.         $message $request->get("message");
  158.         if ($message === null) {
  159.             $message "";
  160.         }
  161.         return $this->render(
  162.             'default/index-no-booking-authorized-company-inactive.html.twig',
  163.             [
  164.                 'username' => $this->getUser(),
  165.                 "organization" => $this->getUser()->getCompanyCodeOps() . ' / ' $this->getUser()->getCompanyName(),
  166.                 "message" => $message
  167.             ]
  168.         );
  169.     }
  170.     /**
  171.      * Generate AWS Signature V4
  172.      *
  173.      * @param Request $request
  174.      *
  175.      * @Route("/aws/sign-v4", options={"expose"=true}, name="aws_sign_upload_v4", methods={"GET"})
  176.      * @return Response
  177.      */
  178.     public function amazonSignatureV4Action(Request $request)
  179.     {
  180.         if (!$signRequest $request->query->get('to_sign')) {
  181.             throw new BadRequestHttpException('You must provide a signature request.');
  182.         }
  183.         $signResponse $this->s3Provider->generateSignatureV4($signRequest);
  184.         return new Response($signResponse);
  185.     }
  186.     /**
  187.      * Generate AWS Signature V2
  188.      *
  189.      * @param Request $request
  190.      *
  191.      * @Route("/aws/sign-v2", options={"expose"=true}, name="aws_sign_upload", methods={"GET"})
  192.      * @return Response
  193.      */
  194.     public function amazonSignatureV2Action(Request $request)
  195.     {
  196.         if (!$signRequest $request->query->get('to_sign')) {
  197.             throw new BadRequestHttpException('You must provide a signature request.');
  198.         }
  199.         $signResponse $this->s3Provider->generateSignatureV2($signRequest);
  200.         return new Response($signResponse);
  201.     }
  202.     /**
  203.      * Change view mode (preview/normale)
  204.      * only used by admin
  205.      *
  206.      * @param Request $request
  207.      * @param SessionInterface $session
  208.      *
  209.      * @Route("/view-mode", options={"expose"=true}, name="view_mode", methods={"GET"})
  210.      * @return Response
  211.      */
  212.     public function viewModeAction(Request $requestSessionInterface $session)
  213.     {
  214.         $viewMode $request->get('mode');
  215.         $session->set('mode'$viewMode);
  216.         return new Response();
  217.     }
  218.     /**
  219.      * @Route("/intern/webservice/footprinted-url", name="get_footprinted_url", options={"expose" = true})
  220.      * @return Response
  221.      */
  222.     public function getFootprintedURLAction(Request $request)
  223.     {
  224.         $tokens = [
  225.             'stateLessPublicId' => $request->get("public"),
  226.             'stateLessPrivateKey' => $request->get("private"),
  227.         ];
  228.         $footprintedUrl $this->webserviceService->generateFootprintedUrl($request->get("url"), $tokens);
  229.         return $this->json($footprintedUrl);
  230.     }
  231.     /**
  232.      * @Route("/intern/webservice/footprinted-url-result", name="get_footprinted_url_result", options={"expose" = true})
  233.      * @return Response
  234.      */
  235.     public function getFootprintedURLResultAction(Request $request)
  236.     {
  237.         $url $request->get("url");
  238.         $client = new Client();
  239.         $response $client->request(
  240.             'GET',
  241.             $url,
  242.             []
  243.         );
  244.         $test = (string)$response->getBody();
  245.         return $this->json($test);
  246.     }
  247.     /**
  248.      * @Route("/mailchimp-synchro-users-details", name="mailchimp_synchro_users_details", options={"expose" = true})
  249.      * @param Request $request
  250.      * @Security("is_granted('ROLE_SUPER_ADMINISTRATOR')")
  251.      * @return Response
  252.      */
  253.     public function mailchimpUserDetailsSynchroAction(Request $request)
  254.     {
  255.         $offset $request->get("offset");
  256.         $count $request->get("count");
  257.         $response $this->newslettersService->syncUserDetailsWithMailchimp($offset$count);
  258.         return $this->json('ok');
  259.     }
  260.     /**
  261.      * @Route("/test-callback", name="test_callback_put", methods={"PUT"})
  262.      * @param Request $request
  263.      * @return Response
  264.      */
  265.     public function testCallbackAction(Request $request)
  266.     {
  267.         return $this->json('ok');
  268.     }
  269.     /**
  270.      * @Route("/test-callback-get", name="test_callback_get", methods={"GET"})
  271.      * @param Request $request
  272.      * @return Response
  273.      */
  274.     public function testCallbackGetAction(Request $request)
  275.     {
  276.         sleep(35);
  277.         return $this->json('ok');
  278.     }
  279.     /**
  280.      * @Route("/test-callback-get-75", name="test_callback_get_75", methods={"GET"})
  281.      * @param Request $request
  282.      * @return Response
  283.      */
  284.     public function testCallbackGet75Action(Request $request)
  285.     {
  286.         sleep(75);
  287.         return $this->json('ok');
  288.     }
  289.     /**
  290.      * @Route("/test-callback/{timeout}", name="test_callback_timeout", methods={"GET", "PUT"})
  291.      * @param Request $request
  292.      * @param string $timeout
  293.      * @return Response
  294.      */
  295.     public function testCallbackTimeoutAction(Request $requeststring $timeout)
  296.     {
  297.         sleep($timeout);
  298.         return $this->json('ok');
  299.     }
  300.     /**
  301.      * @Route("/debug-webservices", name="debug_webservices", options={"expose" = true})
  302.      * @Security("is_granted('ROLE_USER')")
  303.      * @return Response
  304.      */
  305.     public function debugWSAction(Request $request)
  306.     {
  307.         $user $this->getUser();
  308.         $env $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL);
  309.         return $this->render('default/debug-ws.html.twig', [
  310.             'user' => $user,
  311.             'env' => $env
  312.         ]);
  313.     }
  314.     /**
  315.      * @Route("/api-migration", name="api_migration", options={"expose" = true})
  316.      * @Security("is_granted('ROLE_USER')")
  317.      * @return Response
  318.      */
  319.     public function apiMigrationAction(Request $request)
  320.     {
  321.         $user $this->getUser();
  322.         $env $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL);
  323.         return $this->render('default/api-migration.html.twig');
  324.     }
  325. }