src/Controller/ThemesWebsite/Whileresume/Website/PagesController.php line 293

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ThemesWebsite\Whileresume\Website;
  3. use App\Entity\Core\Users;
  4. use App\Entity\Fiches\Articles;
  5. use App\Entity\Fiches\Interactions;
  6. use App\Entity\Pages\Contents;
  7. use App\Entity\Pages\Pages;
  8. use App\Entity\Pages\PagesHasBlocks;
  9. use App\Entity\Pages\SecureContent;
  10. use App\Entity\Pages\SimulationContent;
  11. use App\Entity\Pages\SimulationContentCategories;
  12. use App\Entity\Pages\SimulationContentHasCheck;
  13. use App\Form\Fiches\InteractionsAdminForm;
  14. use App\Form\Fiches\InteractionsForm;
  15. use App\Form\Fiches\InteractionsSimpleForm;
  16. use App\Form\Pages\BeforeSecureContentsForm;
  17. use App\Form\Pages\ReportingEmailForm;
  18. use App\Services\EncryptionService;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\HttpFoundation\Session\Session;
  22. use Symfony\Component\Filesystem\Filesystem;
  23. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  24. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  25. use Symfony\Component\HttpFoundation\StreamedResponse;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use Symfony\Component\HttpFoundation\JsonResponse;
  28. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  29. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  30. use Symfony\Component\Form\Extension\Core\Type\TextType;
  31. use Doctrine\ORM\EntityManagerInterface;
  32. use Psr\Log\LoggerInterface;
  33. use function App\Controller\Vitrine\dump;
  34. /**
  35.  * Gestion des pages
  36.  */
  37. class PagesController extends AbstractController
  38. {
  39.     private $em;
  40.     private $us;
  41.     private $es;
  42.     private $decryptionLogger;
  43.     public function __construct(EntityManagerInterface $em,
  44.                                 \App\Services\Core\Users $us,
  45.                                 EncryptionService $es,
  46.                                 LoggerInterface $decryptionLogger
  47.     ){
  48.         $this->em $em;
  49.         $this->us $us;
  50.         $this->es $es;
  51.         $this->decryptionLogger $decryptionLogger;
  52.     }
  53.     /**
  54.      * 1er niveau
  55.      * @param Request $request
  56.      * @param $folderslug
  57.      * @return mixed
  58.      */
  59.     public function fiche(Request $request$folderslug)
  60.     {
  61.         $themeSelection $_ENV['THEME_BLOG'];
  62.         $session $request->getSession();
  63.         $locale $request->getLocale();
  64.         // Mode TEST
  65.         if($_ENV['APP_ENV'] !== "prod") {
  66.             if($folderslug === "test") {
  67.                 $page $this->em->getRepository(Pages::class)->findOneBy(['name' => 'test']);
  68.                 return $this->render('application/whileresume/website/page_test.html.twig',['page' => $page]);
  69.             }
  70.         }
  71.         // Article sur une page.
  72.         $pageArticle $this->em->getRepository(\App\Entity\Articles\Articles::class)->getPage($locale,$folderslug);
  73.         if($pageArticle !== null) {
  74.             return $this->render('application/whileresume/website/page_article.html.twig', [
  75.                 'article' => $pageArticle
  76.             ]);
  77.         }
  78.         // Simulation de projets
  79.         $contentSC $this->em->getRepository(SimulationContent::class)->findOneBy(['locale' => $locale'identifiant' => $folderslug]);
  80.         if ($contentSC) {
  81.             $checks $this->em->getRepository(SimulationContentHasCheck::class)->findBy(['simulationContent' => $contentSC->getId()]);
  82.             $categories $this->em->getRepository(SimulationContentCategories::class)->findBy(['simulationContent' => $contentSC->getId()]);
  83.             $categoriesOn $this->em->getRepository(SimulationContentCategories::class)->findBy(['simulationContent' => $contentSC->getId(),'onQuotation' => true'details' => true]);
  84.             $categoriesOff $this->em->getRepository(SimulationContentCategories::class)->findBy(['simulationContent' => $contentSC->getId(),'onQuotation' => false'details' => true]);
  85.             return $this->render('application/whileresume/website/page_simulation.html.twig', [
  86.                 'content' => $contentSC,
  87.                 'checks' => $checks,
  88.                 'categories' => $categories,
  89.                 'categoriesOn' => $categoriesOn,
  90.                 'categoriesOff' => $categoriesOff
  91.             ]);
  92.         }
  93.         // Contenu chiffré.
  94.         $contentS $this->em->getRepository(SecureContent::class)->findOneBy(['locale' => $locale'identifiant' => $folderslug]);
  95.         if ($contentS) {
  96.             $attemptKey 'decrypt_attempts_' $folderslug;
  97.             $maxAttempts 5;
  98.             $lockoutTime 60// Temps de verrouillage en secondes (1 minute)
  99.             // Vérifiez si l'utilisateur est temporairement verrouillé
  100.             if ($session->has($attemptKey '_lockout_time') && time() < $session->get($attemptKey '_lockout_time')) {
  101.                 return $this->render('vitrine/'.$themeSelection.'/secure/lockout.html.twig', [
  102.                     'lockout_time' => $session->get($attemptKey '_lockout_time') - time(),
  103.                     'content' => $contentS,
  104.                     'folderslug' => $folderslug
  105.                 ]);
  106.             }
  107.             $attempts $session->get($attemptKey0);
  108.             if ($attempts >= $maxAttempts) {
  109.                 // Verrouillez l'accès pour un certain temps
  110.                 $session->set($attemptKey '_lockout_time'time() + $lockoutTime);
  111.                 $session->remove($attemptKey); // Réinitialisez le compteur de tentatives
  112.                 return $this->render('vitrine/'.$themeSelection.'/secure/lockout.html.twig', [
  113.                     'lockout_time' => $lockoutTime,
  114.                     'content' => $contentS,
  115.                     'folderslug' => $folderslug
  116.                 ]);
  117.             }
  118.             $form $this->createForm(BeforeSecureContentsForm::class, $contentS);
  119.             $form->handleRequest($request);
  120.             if ($form->isSubmitted() && $form->isValid()) {
  121.                 //$data = $form->getData();
  122.                 $data $request->request->all();
  123.                 $dataM $data['before_secure_contents_form'];
  124.                 $key $dataM['identifiantKey'];
  125.                 try {
  126.                     $keyDecrypt $this->es->decrypt($contentS->getIdentifiantKey(), $key);
  127.                     if ($keyDecrypt === "mirtillo") {
  128.                         $descriptionDecrypt "";
  129.                         if(!empty($contentS->getDescription())) {
  130.                             $descriptionDecrypt $this->es->decrypt($contentS->getDescription(), $key);
  131.                         }
  132.                         $descriptionContentDecrypt "";
  133.                         if(!empty($contentS->getDescriptionContent())) {
  134.                             $descriptionContentDecrypt $this->es->decrypt($contentS->getDescriptionContent(), $key);
  135.                         }
  136.                         $session->remove($attemptKey); // Réinitialisez le compteur en cas de succès
  137.                         return $this->render('vitrine/'.$themeSelection.'/secure/content.html.twig', [
  138.                             'content' => $contentS,
  139.                             'descriptionContent' => $descriptionContentDecrypt,
  140.                             'description' => $descriptionDecrypt
  141.                         ]);
  142.                     } else {
  143.                         throw new \Exception("Decryption failed");
  144.                     }
  145.                 } catch (\Exception $e) {
  146.                     // En cas d'échec, incrémentez le compteur
  147.                     $attempts++;
  148.                     $session->set($attemptKey$attempts);
  149.                     // Journalisation de l'échec
  150.                     $this->decryptionLogger->warning('Tentative de décryptage échouée', [
  151.                         'user_id' => $this->getUser() ? $this->getUser()->getId() : 'anonyme',
  152.                         'ip' => $request->getClientIp(),
  153.                         'folderslug' => $folderslug,
  154.                         'timestamp' => time(),
  155.                         'tentative' => $attempts
  156.                     ]);
  157.                 }
  158.                 return $this->redirectToRoute('pages_fiche', ['folderslug' => $folderslug]);
  159.             }
  160.             return $this->render('application/whileresume/website/secure/key_content.html.twig', [
  161.                 'form' => $form->createView(),
  162.                 'content' => $contentS
  163.             ]);
  164.         }
  165.         // Contenu simplifié.
  166.         $content $this->em->getRepository(Contents::class)->getPage($locale,$folderslug);
  167.         if($content) {
  168.             return $this->render('application/whileresume/website/page_content.html.twig',[
  169.                 'page' => $content
  170.             ]);
  171.         }
  172.         $premiumContent $this->em->getRepository(Articles::class)->findOneBy(['locale' => $locale'folderSlug' => $folderslug'status' => 'ONLINE']);
  173.         if($premiumContent) {
  174.             $user $this->getUser();
  175.             $interactions $this->em->getRepository(Interactions::class)->getThread($premiumContent->getId(),$user);
  176.             $countInteractions $this->em->getRepository(Interactions::class)->countThreads($premiumContent->getId());
  177.             $questions $this->em->getRepository(Interactions::class)->getQuestions($premiumContent->getId());
  178.             $intObj = new Interactions();
  179.             $intObj->setUser($user);
  180.             $intObj->setArticle($premiumContent);
  181.             $intObj->setLocked(false);
  182.             // Interactions
  183.             $formInteractions $this->createForm(InteractionsForm::class,$intObj);
  184.             $formInteractions->handleRequest($request);
  185.             if ($formInteractions->isSubmitted() && $formInteractions->isValid()) {
  186.                 $this->em->persist($intObj);
  187.                 $this->em->flush();
  188.                 return $this->redirectToRoute('pages_fiche',['folderslug' => $folderslug]);
  189.             }
  190.             // Envoyer par mail.
  191.             $formReporting $this->createForm(ReportingEmailForm::class);
  192.             $formReporting->handleRequest($request);
  193.             if ($formReporting->isSubmitted() && $formReporting->isValid()) {
  194.                 $data $request->request->all();
  195.                 dump($data);
  196.                 die;
  197.                 return $this->redirectToRoute('pages_fiche',['folderslug' => $folderslug]);
  198.             }
  199.             return $this->render('application/whileresume/website/premium/content.html.twig',[
  200.                 'page' => $premiumContent,
  201.                 'fiche' => $premiumContent,
  202.                 'formInteractions' => $formInteractions->createView(),
  203.                 'formReporting' => $formReporting->createView(),
  204.                 'interactions' => $interactions,
  205.                 'countInteractions' => $countInteractions,
  206.                 'questions' => $questions
  207.             ]);
  208.         }
  209.         $page $this->em->getRepository(Pages::class)->getPage($locale,$folderslug);
  210.         if(!$page) {
  211.             return $this->redirectToRoute('homepage');
  212.         }
  213.         $user $this->getUser();
  214.         if($user == null) {
  215.             if($page->getType() == "brouillon") {
  216.                 return $this->redirectToRoute('homepage');
  217.             }
  218.             if(!empty($page->getRedirect())) {
  219.                 return $this->redirect($page->getRedirect());
  220.             }
  221.         } else {
  222.             $grant $this->em->getRepository(Users::class)->userHasRole($user->getId(),"ROLE_SUPER_ADMIN");
  223.             if($grant == "0") {
  224.                 if($page->getType() == "brouillon") {
  225.                     return $this->redirectToRoute('homepage');
  226.                 }
  227.                 if(!empty($page->getRedirect())) {
  228.                     return $this->redirect($page->getRedirect());
  229.                 }
  230.             }
  231.         }
  232.         $blocks $this->em->getRepository(PagesHasBlocks::class)->findBy(['page' => $page'type' => 'prod''startPage' => false],['sequence' => 'ASC']);
  233.         $page->setViews((int)$page->getViews() + 1);
  234.         $this->em->persist($page);
  235.         $this->em->flush();
  236.         return $this->render('application/whileresume/website/page.html.twig',[
  237.             'page' => $page,
  238.             'blocks' => $blocks
  239.         ]);
  240.     }
  241.     /**
  242.      * 2ème niveau
  243.      * @param Request $request
  244.      * @param $folderslug
  245.      * @param $folderslug2
  246.      * @return mixed
  247.      */
  248.     public function fiche2(Request $request$folderslug$folderslug2)
  249.     {
  250.         $themeSelection $_ENV['THEME_BLOG'];
  251.         $locale $request->getLocale();
  252.         $user $this->getUser();
  253.         $pageArticle $this->em->getRepository(\App\Entity\Articles\Articles::class)->getPage($locale,$folderslug,$folderslug2);
  254.         if($pageArticle !== null) {
  255.             return $this->render('application/whileresume/website/page_article.html.twig', [
  256.                 'article' => $pageArticle
  257.             ]);
  258.         }
  259.         $content $this->em->getRepository(Contents::class)->getPage($locale,$folderslug,$folderslug2);
  260.         if($content) {
  261.             return $this->render('application/whileresume/website/page_content.html.twig',[
  262.                 'page' => $content
  263.             ]);
  264.         }
  265.         $premiumContent $this->em->getRepository(Articles::class)->findOneBy(['locale' => $locale'folderSlug' => $folderslug'folderSlug2' => $folderslug2'status' => 'ONLINE']);
  266.         if($premiumContent) {
  267.             $user $this->getUser();
  268.             $interactions $this->em->getRepository(Interactions::class)->getThread($premiumContent->getId(),$user);
  269.             $countInteractions $this->em->getRepository(Interactions::class)->countThreads($premiumContent->getId());
  270.             $questions $this->em->getRepository(Interactions::class)->getQuestions($premiumContent->getId());
  271.             $intObj = new Interactions();
  272.             $intObj->setUser($user);
  273.             $intObj->setArticle($premiumContent);
  274.             $intObj->setLocked(false);
  275.             // Interactions
  276.             $formInteractions $this->createForm(InteractionsForm::class,$intObj);
  277.             $formInteractions->handleRequest($request);
  278.             if ($formInteractions->isSubmitted() && $formInteractions->isValid()) {
  279.                 $this->em->persist($intObj);
  280.                 $this->em->flush();
  281.                 return $this->redirectToRoute('pages_fiche',['folderslug' => $folderslug]);
  282.             }
  283.             return $this->render('application/whileresume/website/premium/content.html.twig',[
  284.                 'page' => $premiumContent,
  285.                 'fiche' => $premiumContent,
  286.                 'formInteractions' => $formInteractions->createView(),
  287.                 'interactions' => $interactions,
  288.                 'countInteractions' => $countInteractions,
  289.                 'questions' => $questions
  290.             ]);
  291.         }
  292.         $page $this->em->getRepository(Pages::class)->getPage($locale,$folderslug,$folderslug2);
  293.         if(!$page) {
  294.             return $this->redirectToRoute('homepage');
  295.         }
  296.         if($user == null) {
  297.             if($page->getType() == "brouillon") {
  298.                 return $this->redirectToRoute('homepage');
  299.             }
  300.             if(!empty($page->getRedirect())) {
  301.                 return $this->redirect($page->getRedirect());
  302.             }
  303.         } else {
  304.             $grant $this->em->getRepository(Users::class)->userHasRole($user->getId(),"ROLE_SUPER_ADMIN");
  305.             if($grant == "0") {
  306.                 if($page->getType() == "brouillon") {
  307.                     return $this->redirectToRoute('homepage');
  308.                 }
  309.                 if(!empty($page->getRedirect())) {
  310.                     return $this->redirect($page->getRedirect());
  311.                 }
  312.             }
  313.         }
  314.         $blocks $this->em->getRepository(PagesHasBlocks::class)->findBy(['page' => $page'type' => 'prod''startPage' => false],['sequence' => 'ASC']);
  315.         $page->setViews((int)$page->getViews() + 1);
  316.         $this->em->persist($page);
  317.         $this->em->flush();
  318.         return $this->render('application/whileresume/website/page.html.twig',[
  319.             'page' => $page,
  320.             'blocks' => $blocks
  321.         ]);
  322.     }
  323.     /**
  324.      * 3ème niveau
  325.      * @param Request $request
  326.      * @param $folderslug
  327.      * @param $folderslug2
  328.      * @param $folderslug3
  329.      * @return mixed
  330.      */
  331.     public function fiche3(Request $request$folderslug$folderslug2$folderslug3)
  332.     {
  333.         $themeSelection $_ENV['THEME_BLOG'];
  334.         $locale $request->getLocale();
  335.         $user $this->getUser();
  336.         $pageArticle $this->em->getRepository(\App\Entity\Articles\Articles::class)->getPage($locale,$folderslug,$folderslug2,$folderslug3);
  337.         if($pageArticle !== null) {
  338.             return $this->render('application/whileresume/website/page_article.html.twig', [
  339.                 'article' => $pageArticle
  340.             ]);
  341.         }
  342.         $content $this->em->getRepository(Contents::class)->getPage($locale,$folderslug,$folderslug2,$folderslug3);
  343.         if($content) {
  344.             return $this->render('application/whileresume/website/page_content.html.twig',[
  345.                 'page' => $content
  346.             ]);
  347.         }
  348.         $premiumContent $this->em->getRepository(Articles::class)->findOneBy(['locale' => $locale'folderSlug' => $folderslug'folderSlug2' => $folderslug2'folderSlug3' => $folderslug3'status' => 'ONLINE']);
  349.         if($premiumContent) {
  350.             $interactions $this->em->getRepository(Interactions::class)->getThread($premiumContent->getId(),$user);
  351.             $countInteractions $this->em->getRepository(Interactions::class)->countThreads($premiumContent->getId());
  352.             $questions $this->em->getRepository(Interactions::class)->getQuestions($premiumContent->getId());
  353.             $intObj = new Interactions();
  354.             $intObj->setUser($user);
  355.             $intObj->setArticle($premiumContent);
  356.             $intObj->setLocked(false);
  357.             // Interactions
  358.             $formInteractions $this->createForm(InteractionsForm::class,$intObj);
  359.             $formInteractions->handleRequest($request);
  360.             if ($formInteractions->isSubmitted() && $formInteractions->isValid()) {
  361.                 $this->em->persist($intObj);
  362.                 $this->em->flush();
  363.                 return $this->redirectToRoute('pages_fiche',['folderslug' => $folderslug]);
  364.             }
  365.             return $this->render('application/whileresume/website/premium/content.html.twig',[
  366.                 'page' => $premiumContent,
  367.                 'fiche' => $premiumContent,
  368.                 'formInteractions' => $formInteractions->createView(),
  369.                 'interactions' => $interactions,
  370.                 'countInteractions' => $countInteractions,
  371.                 'questions' => $questions
  372.             ]);
  373.         }
  374.         $page $this->em->getRepository(Pages::class)->getPage($locale,$folderslug,$folderslug2,$folderslug3);
  375.         if(!$page) {
  376.             return $this->redirectToRoute('homepage');
  377.         }
  378.         $user $this->getUser();
  379.         if($user == null) {
  380.             if($page->getType() == "brouillon") {
  381.                 return $this->redirectToRoute('homepage');
  382.             }
  383.             if(!empty($page->getRedirect())) {
  384.                 return $this->redirect($page->getRedirect());
  385.             }
  386.         } else {
  387.             $grant $this->em->getRepository(Users::class)->userHasRole($user->getId(),"ROLE_SUPER_ADMIN");
  388.             if($grant == "0") {
  389.                 if($page->getType() == "brouillon") {
  390.                     return $this->redirectToRoute('homepage');
  391.                 }
  392.                 if(!empty($page->getRedirect())) {
  393.                     return $this->redirect($page->getRedirect());
  394.                 }
  395.             }
  396.         }
  397.         $blocks $this->em->getRepository(PagesHasBlocks::class)->findBy(['page' => $page'type' => 'prod''startPage' => false],['sequence' => 'ASC']);
  398.         $page->setViews((int)$page->getViews() + 1);
  399.         $this->em->persist($page);
  400.         $this->em->flush();
  401.         return $this->render('application/whileresume/website/page.html.twig',[
  402.             'page' => $page,
  403.             'blocks' => $blocks
  404.         ]);
  405.     }
  406. }