src/Controller/PageGeneratorController.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Twig\Environment;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\Finder\Finder;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\EventDispatcher\GenericEvent;
  12. use Symfony\Component\Form\FormInterface;
  13. use Symfony\Component\Security\Core\Security;
  14. use Symfony\Component\Routing\RequestContext;
  15. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  16. use Sylius\Component\Channel\Context\ChannelContextInterface;
  17. use App\Repository\UserRepository;
  18. use App\Service\UserService;
  19. use Vanilla\JsConnect\JsConnect;
  20. final class PageGeneratorController extends AbstractController
  21. {
  22. /** @var Environment */
  23. private $twig;
  24. /** @var ChannelContextInterface */
  25. private $channelContext;
  26. private Jsconnect $jsconnect;
  27. public function __construct(Environment $twig, Jsconnect $jsconnect)
  28. {
  29. $this->twig = $twig;
  30. $this->jsconnect = $jsconnect;
  31. }
  32. public function menuAction(): Response
  33. {
  34. return $this->render('@SyliusShop/Menu/_pageMenu.html.twig');
  35. }
  36. /**
  37. * @Route("/old_version", name="old_version")
  38. */
  39. public function oldversionAction(Request $request): Response
  40. {
  41. $finderwindows64 = new Finder();
  42. $windowsfiles64 = $finderwindows64->files()->name('*.zip')->in($this->get('kernel')->getProjectDir() . "/public/versions/old/Windows/x64");
  43. $finderwindows32 = new Finder();
  44. $windowsfiles32 = $finderwindows32->files()->name('*.zip')->in($this->get('kernel')->getProjectDir() . "/public/versions/old/Windows/x86");
  45. $findermac = new Finder();
  46. $macfiles = $findermac->files()->name('*.zip')->in($this->get('kernel')->getProjectDir() . "/public/versions/old/OSX");
  47. return $this->render('page_generator/oldversion.html.twig', array('windowsfiles64' => $windowsfiles64,'windowsfiles32' => $windowsfiles32, 'macfiles' => $macfiles));
  48. }
  49. /**
  50. * @Route("/download", name="download")
  51. public function downloadAction(Request $request): Response
  52. {
  53. return $this->render('page_generator/download.html.twig');
  54. }
  55. */
  56. /**
  57. * @Route("/formation", name="formation")
  58. */
  59. public function formationAction(Request $request): Response
  60. {
  61. return $this->render('page_generator/formation.html.twig');
  62. }
  63. /**
  64. * @Route("/forum", name="forum")
  65. */
  66. public function forumAction(Request $request, UserService $userService): Response
  67. {
  68. $user = $this->getUser();
  69. // Récupérer les paramètres JSConnect
  70. $clientID = $this->getParameter('JSclientIDv2');
  71. $secret = $this->getParameter('JSsecretv2');
  72. $signedIn = false;
  73. if ($user === null || !$user->isVerified()) {
  74. // Retourner une chaîne vide si l'utilisateur n'est pas connecté ou non vérifié
  75. return $this->render('page_generator/embedforum.html.twig', ['myssostring' => '']);
  76. }
  77. $this->jsconnect->setSigningCredentials($clientID, $secret);
  78. // Vérifier si l'utilisateur est vérifié
  79. $signedIn = true;
  80. // Récupérer les informations du client
  81. $customer = $userService->getCustomerByUser($user);
  82. $payload = json_encode([
  83. 'client_id' => $clientID,
  84. 'uniqueid' => $user->getId(),
  85. 'name' => $customer->getPseudo(),
  86. 'email' => $customer->getEmail(),
  87. 'client_id' => $clientID,
  88. 'timestamp' => time(),
  89. ]);
  90. // Renseigner les informations utilisateur
  91. $this->jsconnect->setUniqueID($user->getId())
  92. ->setName($customer->getPseudo())
  93. ->setEmail($customer->getEmail());
  94. $signature = hash_hmac('sha1', $payload, $secret);
  95. // Générer le SSO string
  96. $ssoString = base64_encode($payload) . ' ' . $signature;
  97. // Générer la chaîne SSO pour Vanilla Forums
  98. //$ssoString = $this->jsconnect->ssoString($userdata, $clientID, $secret);
  99. // Rendre le template avec la chaîne SSO
  100. return $this->render('page_generator/embedforum.html.twig', [
  101. 'myssostring' => $ssoString,
  102. ]);
  103. }
  104. /**
  105. * @Route("/wiki", name="wiki")
  106. */
  107. public function wikiAction(Request $request): Response
  108. {
  109. return $this->render('page_generator/wiki.html.twig');
  110. }
  111. /**
  112. * @Route("/redirectlogin", name="redirectlogin")
  113. */
  114. public function redirectloginAction(Request $request): Response
  115. {
  116. $context = new RequestContext();
  117. $context->fromRequest(Request::createFromGlobals());
  118. $url = $this->generateUrl('sylius_shop_login', [
  119. '_locale' => 'fr',
  120. ], UrlGeneratorInterface::ABSOLUTE_URL);
  121. $js = '<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script><script type="text/javascript">jQuery(document).ready( function() {
  122. top.location = "' . $url . '";});</script>';
  123. $response = new Response();
  124. $response->prepare($request);
  125. $response->setContent($js);
  126. $response->send();
  127. //return $this->redirect($url);
  128. //return $this->redirectToRoute('sylius_shop_login', [], 301);
  129. }
  130. /**
  131. * @Route("/redirectlogout", name="redirectlogout")
  132. */
  133. public function redirectlogoutAction(Request $request): Response
  134. {
  135. $context = new RequestContext();
  136. $context->fromRequest(Request::createFromGlobals());
  137. $url = $this->generateUrl('sylius_shop_logout', ['_locale' => 'fr',], UrlGeneratorInterface::ABSOLUTE_URL);
  138. $js = '<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script><script type="text/javascript">jQuery(document).ready( function() {
  139. top.location = "' . $url . '";});</script>';
  140. $response = new Response();
  141. $response->prepare($request);
  142. $response->setContent($js);
  143. $response->send();
  144. }
  145. /**
  146. * @Route("/redirectregister", name="redirectregister")
  147. */
  148. public function redirectregisterAction(Request $request): Response
  149. {
  150. $context = new RequestContext();
  151. $context->fromRequest(Request::createFromGlobals());
  152. $url = $this->generateUrl('sylius_shop_register', ['_locale' => 'fr',], UrlGeneratorInterface::ABSOLUTE_URL);
  153. $js = '<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script><script type="text/javascript">jQuery(document).ready( function() { top.location = "' . $url . '";});</script>';
  154. $response = new Response();
  155. $response->prepare($request);
  156. $response->setContent($js);
  157. $response->send();
  158. // return $this->redirect($url);
  159. //return $this->redirectToRoute('sylius_shop_register', [], 301);
  160. }
  161. /**
  162. * @Route("/electronique", name="electronique")
  163. */
  164. public function electroniqueAction(Request $request): Response
  165. {
  166. $code = array('Board_Taxons','DMX_HF','PWM_DIMMER_Taxon', 'HF_PROJECTOR__Taxon','books');
  167. return $this->render('page_generator/electronique.html.twig', array('code' => $code, 'maxresult' => -1));
  168. }
  169. /**
  170. * @Route("/features", name="features")
  171. */
  172. public function featuresAction(Request $request): Response
  173. {
  174. return $this->render('page_generator/features.html.twig');
  175. }
  176. /**
  177. * @Route("/liens", name="liens")
  178. */
  179. public function liensAction(Request $request): Response
  180. {
  181. return $this->render('page_generator/liens.html.twig');
  182. }
  183. /**
  184. * @Route("/about", name="about")
  185. */
  186. public function aboutAction(Request $request): Response
  187. {
  188. return $this->render('page_generator/about.html.twig');
  189. }
  190. /**
  191. * @Route("/shipping", name="shipping")
  192. */
  193. public function deliveryAction(Request $request): Response
  194. {
  195. return $this->render('page_generator/shipping.html.twig');
  196. }
  197. /**
  198. * @Route("/FAQ", name="FAQ")
  199. */
  200. public function FAQAction(Request $request): Response
  201. {
  202. return $this->render('page_generator/FAQ.html.twig');
  203. }
  204. /**
  205. * @Route("/privacy", name="privacy")
  206. */
  207. public function privacyAction(Request $request): Response
  208. {
  209. return $this->render('page_generator/privacy.html.twig');
  210. }
  211. /**
  212. * @Route("/return", name="return")
  213. */
  214. public function returnAction(Request $request): Response
  215. {
  216. return $this->render('page_generator/return.html.twig');
  217. }
  218. /**
  219. * @Route("/terms", name="terms")
  220. */
  221. public function termsAction(Request $request): Response
  222. {
  223. return $this->render('page_generator/terms.html.twig');
  224. }
  225. /**
  226. * @Route("/confirmationresend", name="confirmationresend")
  227. */
  228. public function resendVerificationTokenfromMailAction(Request $request): Response
  229. {
  230. if ($request->getMethod() == Request::METHOD_POST)
  231. {
  232. $email = $request->request->get('emailverif');
  233. if (null !== $email)
  234. {
  235. $customer = $this->container->get('sylius.repository.customer')->findOneBy(['email' => $email ]);
  236. $user = $customer->getUser();
  237. if (null === $user) {
  238. $this->addTranslatedFlash('error', 'sylius.user.verify_no_user');
  239. return $this->redirectToRoute('sylius_shop_login');
  240. }
  241. else if (null !== $user->getVerifiedAt()) {
  242. $errorMessage = $this->getSyliusAttribute(
  243. $request,
  244. 'error_flash',
  245. 'sylius.user.verify_verified_email'
  246. );
  247. $this->addTranslatedFlash('error', 'sylius.user.verify_verified_email');
  248. return $this->redirectToRoute('sylius_shop_login');
  249. }
  250. }
  251. else
  252. {
  253. $this->addTranslatedFlash('error', 'Please give a valide email');
  254. return $this->redirectToRoute('sylius_shop_login');
  255. }
  256. }
  257. $sender = $this->container->get('sylius.email_sender');
  258. $logpath = 'https://www.hephaestos.eu/build/img/baniere1024x768.png';
  259. $localeCode = $this->get('sylius.context.locale')->getLocaleCode();
  260. $channel = $this->container->get('sylius.context.channel')->getChannel();
  261. $sender->send(\Sylius\Bundle\UserBundle\Mailer\Emails::EMAIL_VERIFICATION_TOKEN, [$email], ['user' => $user, 'channel' => $channel, 'localeCode' => $localeCode, 'image_src' => $logpath]);
  262. // $sender->send(\Sylius\Bundle\UserBundle\Mailer\Emails::EMAIL_VERIFICATION_TOKEN, [$email], ['user' => $user, 'image_src' => $logpath]);
  263. /** @var GeneratorInterface $tokenGenerator */
  264. /* $tokenGenerator = $this->container->get(sprintf('sylius.%s.token_generator.email_verification', $user->getUsername()));
  265. $user->setEmailVerificationToken($tokenGenerator->generate());
  266. $this->manager->flush();*/
  267. /* $eventDispatcher = $this->container->get('event_dispatcher');
  268. $eventDispatcher->dispatch(UserEvents::REQUEST_VERIFICATION_TOKEN, new GenericEvent($user));*/
  269. $this->addTranslatedFlash('success', 'sylius.user.verify_email_request');
  270. return $this->redirectToRoute('sylius_shop_login');
  271. }
  272. /**
  273. * {@inheritdoc}
  274. */
  275. protected function addTranslatedFlash(string $type, string $message): void
  276. {
  277. $translator = $this->container->get('translator');
  278. $this->container->get('session')->getFlashBag()->add($type, @$this->translator->trans($message, [], 'flashes'));
  279. }
  280. }