<?php
namespace App\Controller;
use App\Business\ContactUs;
use App\Entity\UserPreference;
use App\Extern\NeosService;
use App\Extern\XrmService;
use App\Form\ContactUsType;
use App\Services\ApplicationRoleService;
use App\Services\DashboardService;
use App\Services\Elastic\ElasticNeosService;
use App\Services\NewslettersService;
use App\Services\NotificationSenderHelperService;
use App\Services\S3Provider;
use App\Services\WebserviceService;
use GuzzleHttp\Client;
use JSend\JSendResponse;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security as SecurityInterface;
class DefaultController extends BaseController
{
/** @var S3Provider $s3Provider */
protected $s3Provider;
/** @var ElasticNeosService $elasticNeosService */
protected $elasticNeosService;
/** @var ApplicationRoleService $accessRightsService */
protected $accessRightsService;
/** @var NeosService $neosService */
protected $neosService;
/** @var NotificationSenderHelperService $notificationSenderHelperService */
protected $notificationSenderHelperService;
/**
* @var WebserviceService $webserviceService
*/
protected $webserviceService;
/** @var NewslettersService $newslettersService */
private $newslettersService;
/** @var DashboardService $dashboardService */
private $dashboardService;
private $xrmService;
/**
* DefaultController constructor.
*
* @param S3Provider $s3Provider
* @param ElasticNeosService $elasticNeosService
* @param ApplicationRoleService $accessRightsService
* @param NeosService $neosService
* @param NotificationSenderHelperService $notificationSenderHelperService
* @param SecurityInterface $security
* @param NewslettersService $newslettersService
* @param DashboardService $dashboardService
* @param WebserviceService $webserviceService
* @param XrmService $xrmService
*/
public function __construct(
S3Provider $s3Provider,
ElasticNeosService $elasticNeosService,
ApplicationRoleService $accessRightsService,
NeosService $neosService,
NewslettersService $newslettersService,
NotificationSenderHelperService $notificationSenderHelperService,
SecurityInterface $security,
DashboardService $dashboardService,
WebserviceService $webserviceService,
XrmService $xrmService
)
{
parent::__construct($security);
$this->s3Provider = $s3Provider;
$this->newslettersService = $newslettersService;
$this->elasticNeosService = $elasticNeosService;
$this->accessRightsService = $accessRightsService;
$this->neosService = $neosService;
$this->notificationSenderHelperService = $notificationSenderHelperService;
$this->dashboardService = $dashboardService;
$this->webserviceService = $webserviceService;
$this->xrmService = $xrmService;
}
/**
* expose = true to be accessible forom javascript.
* @Route("/", name="homepage", options={"expose" = true})
*
* @return Response
*/
public function indexAction()
{
$isRegistered = false;
if ($this->getUser() != null) {
$isRegistered = $this->newslettersService->isLoggedInUserRegisteredToInsights($this->getUser()->getUid());
}
$adminUrl = null;
return $this->render('default/homepage.html.twig', [
'isRegistered' => $isRegistered,
BaseController::PARAM_ADMIN_URL => $adminUrl
]);
}
/**
* Temporary access to the homepage for admin
* @Route("/homepage", name="homepage_intern")
*
* @return Response
*/
public function internAction()
{
return $this->indexAction();
}
/**
* Auth check
*
* @Route("/auth/check", name="eurovision_security_login_check", methods={"GET"})
*/
public function authCheckAction(Request $request)
{
return $this->indexAction();
}
/**
* @Route("/not-authorized", name="eurovision_not_authorized")
*/
public function notAuthorizedAction(Request $request)
{
$message = $request->get("message");
if ($message === null) {
$message = "";
}
return $this->render(
'default/index-notAuthorized.html.twig',
['username' => $this->getUser(), "message" => $message]
);
}
/**
* @Route("/no-booking-authorized", name="eurovision_no_booking_authorized")
*/
public function notAuthorizedToBookAction(Request $request)
{
$message = $request->get("message");
if ($message === null) {
$message = "";
}
$parts = explode('@', $this->getUser()->getEmail());
$domain = array_pop($parts);
$organization = $this->xrmService->getOrganizationsRelatedToSpecificEmailDomain($domain);
return $this->render(
'default/index-no-booking-authorized.html.twig',
['username' => $this->getUser(), "organizationMappingPossible" => count($organization) > 0, "message" => $message]
);
}
/**
* @Route("/no-booking-authorized-company-inactive", name="eurovision_no_booking_authorized_company_inactive")
*/
public function notAuthorizedToBookCompanyInactiveAction(Request $request)
{
$message = $request->get("message");
if ($message === null) {
$message = "";
}
return $this->render(
'default/index-no-booking-authorized-company-inactive.html.twig',
[
'username' => $this->getUser(),
"organization" => $this->getUser()->getCompanyCodeOps() . ' / ' . $this->getUser()->getCompanyName(),
"message" => $message
]
);
}
/**
* Generate AWS Signature V4
*
* @param Request $request
*
* @Route("/aws/sign-v4", options={"expose"=true}, name="aws_sign_upload_v4", methods={"GET"})
* @return Response
*/
public function amazonSignatureV4Action(Request $request)
{
if (!$signRequest = $request->query->get('to_sign')) {
throw new BadRequestHttpException('You must provide a signature request.');
}
$signResponse = $this->s3Provider->generateSignatureV4($signRequest);
return new Response($signResponse);
}
/**
* Generate AWS Signature V2
*
* @param Request $request
*
* @Route("/aws/sign-v2", options={"expose"=true}, name="aws_sign_upload", methods={"GET"})
* @return Response
*/
public function amazonSignatureV2Action(Request $request)
{
if (!$signRequest = $request->query->get('to_sign')) {
throw new BadRequestHttpException('You must provide a signature request.');
}
$signResponse = $this->s3Provider->generateSignatureV2($signRequest);
return new Response($signResponse);
}
/**
* Change view mode (preview/normale)
* only used by admin
*
* @param Request $request
* @param SessionInterface $session
*
* @Route("/view-mode", options={"expose"=true}, name="view_mode", methods={"GET"})
* @return Response
*/
public function viewModeAction(Request $request, SessionInterface $session)
{
$viewMode = $request->get('mode');
$session->set('mode', $viewMode);
return new Response();
}
/**
* @Route("/intern/webservice/footprinted-url", name="get_footprinted_url", options={"expose" = true})
* @return Response
*/
public function getFootprintedURLAction(Request $request)
{
$tokens = [
'stateLessPublicId' => $request->get("public"),
'stateLessPrivateKey' => $request->get("private"),
];
$footprintedUrl = $this->webserviceService->generateFootprintedUrl($request->get("url"), $tokens);
return $this->json($footprintedUrl);
}
/**
* @Route("/intern/webservice/footprinted-url-result", name="get_footprinted_url_result", options={"expose" = true})
* @return Response
*/
public function getFootprintedURLResultAction(Request $request)
{
$url = $request->get("url");
$client = new Client();
$response = $client->request(
'GET',
$url,
[]
);
$test = (string)$response->getBody();
return $this->json($test);
}
/**
* @Route("/mailchimp-synchro-users-details", name="mailchimp_synchro_users_details", options={"expose" = true})
* @param Request $request
* @Security("is_granted('ROLE_SUPER_ADMINISTRATOR')")
* @return Response
*/
public function mailchimpUserDetailsSynchroAction(Request $request)
{
$offset = $request->get("offset");
$count = $request->get("count");
$response = $this->newslettersService->syncUserDetailsWithMailchimp($offset, $count);
return $this->json('ok');
}
/**
* @Route("/test-callback", name="test_callback_put", methods={"PUT"})
* @param Request $request
* @return Response
*/
public function testCallbackAction(Request $request)
{
return $this->json('ok');
}
/**
* @Route("/test-callback-get", name="test_callback_get", methods={"GET"})
* @param Request $request
* @return Response
*/
public function testCallbackGetAction(Request $request)
{
sleep(35);
return $this->json('ok');
}
/**
* @Route("/test-callback-get-75", name="test_callback_get_75", methods={"GET"})
* @param Request $request
* @return Response
*/
public function testCallbackGet75Action(Request $request)
{
sleep(75);
return $this->json('ok');
}
/**
* @Route("/test-callback/{timeout}", name="test_callback_timeout", methods={"GET", "PUT"})
* @param Request $request
* @param string $timeout
* @return Response
*/
public function testCallbackTimeoutAction(Request $request, string $timeout)
{
sleep($timeout);
return $this->json('ok');
}
/**
* @Route("/debug-webservices", name="debug_webservices", options={"expose" = true})
* @Security("is_granted('ROLE_USER')")
* @return Response
*/
public function debugWSAction(Request $request)
{
$user = $this->getUser();
$env = $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL);
return $this->render('default/debug-ws.html.twig', [
'user' => $user,
'env' => $env
]);
}
/**
* @Route("/api-migration", name="api_migration", options={"expose" = true})
* @Security("is_granted('ROLE_USER')")
* @return Response
*/
public function apiMigrationAction(Request $request)
{
$user = $this->getUser();
$env = $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL);
return $this->render('default/api-migration.html.twig');
}
}