src/Controller/AppController.php line 120

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AccountingFirm;
  4. use App\Entity\MailjetApi;
  5. use App\Entity\PipelineIdentiteVisuelle;
  6. use App\Entity\StakeholderCategory;
  7. use App\Entity\StakeholderSubscriptionType;
  8. use App\Entity\UsefulLink;
  9. use App\Entity\User;
  10. use App\Repository\AccountingFirmRepository;
  11. use App\Repository\EmailBlacklistRepository;
  12. use App\Repository\MailingCommunicationRepository;
  13. use App\Repository\MailjetApiRepository;
  14. use App\Repository\MailjetApiTypeRepository;
  15. use App\Repository\PipelineIdentiteVisuelleRepository;
  16. use App\Repository\StakeholderRepository;
  17. use App\Repository\UserRepository;
  18. use App\Services\HelpersFirmsService;
  19. use App\Services\LagenceExpertService;
  20. use App\Services\Mailing;
  21. use App\Services\MailjetApiEncryptionService;
  22. use App\Services\MailjetService;
  23. use App\Services\TrelloService;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use GuzzleHttp\Client;
  26. use Psr\Log\LoggerInterface;
  27. use Qferrer\Mjml\Twig\MjmlExtension;
  28. use Symfony\Component\HttpFoundation\JsonResponse;
  29. use Symfony\Component\HttpFoundation\Request;
  30. use Symfony\Component\HttpFoundation\Response;
  31. use Symfony\Component\Routing\Annotation\Route;
  32. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  33. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  34. use Symfony\Component\Filesystem\Filesystem;
  35. use Twig\Environment;
  36. class AppController extends AbstractController
  37. {
  38.     #[Route(name'app_home')]
  39.     public function index(): Response
  40.     {
  41.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  42.         $changemdp $this->getUser()->getActivationToken();
  43.         if (is_null($this->getUser()->getAccountingFirm()) && is_null($this->getUser()->getAffiliate()) && !in_array("ROLE_ADMIN"$this->getUser()->getRoles())) {
  44.             return $this->redirectToRoute('actuality_dashboard');
  45.         }
  46.         if ($this->getUser()->getAffiliate()) {
  47.             return $this->redirectToRoute('app_affiliate_request');
  48.         }
  49.         return $this->redirectToRoute('app_dashboard');
  50.         return $this->render('app/index.html.twig', [
  51.             'controller_name' => 'AppController',
  52.             'mdp' => $changemdp,
  53.         ]);
  54.     }
  55.     #[IsGranted('ROLE_USER')]
  56.     #[Route(path'/firstConnectionYes'name'ActivationTokenY'methods: ['GET''POST'])]
  57.     public function ActivationTokenY(EntityManagerInterface $em): Response
  58.     {
  59.         $user $this->getUser();
  60.         $user->setActivationToken(true);
  61.         $em->flush();
  62.         return $this->redirectToRoute('app_forgot_password_request');
  63.     }
  64.     #[IsGranted('ROLE_USER')]
  65.     #[Route(path'/firstConnectionNo'name'ActivationTokenN'methods: ['GET''POST'])]
  66.     public function ActivationTokenN(EntityManagerInterface $em): Response
  67.     {
  68.         $user $this->getUser();
  69.         $user->setActivationToken(true);
  70.         $em->flush();
  71.         return $this->redirectToRoute('app_home');
  72.     }
  73.     #[Route(path'/script-crypt-api-key'name'script-crypt-api-key'methods: ['GET''POST'])]
  74.     public function scriptCryptApiKey(EntityManagerInterface $emMailjetApiTypeRepository $apiTypeRepositoryMailjetApiRepository $mailjetApiRepositoryMailjetApiEncryptionService $mailjetApiEncryptionService): Response
  75.     {
  76.         $mailjetApis $mailjetApiRepository->findAll();
  77.         foreach ($mailjetApis as $mailjetApi) {
  78.             $mailjetApiEncryptionService->encryptMailjetApi($mailjetApi);
  79.             $em->persist($mailjetApi);
  80.         }
  81.         $em->flush();
  82.         return $this->redirectToRoute('app_home');
  83.     }
  84.     #[Route(path'/script-crypt-api-key/{id}'name'script-crypt-api-key-one'methods: ['GET''POST'])]
  85.     public function scriptCryptApiKeyOne(string $idEntityManagerInterface $emMailjetApiRepository $mailjetApiRepositoryMailjetApiEncryptionService $mailjetApiEncryptionService): Response
  86.     {
  87.         $mailjetApi $mailjetApiRepository->findOneBy(['id' => $id]);
  88.         $mailjetApiEncryptionService->encryptMailjetApi($mailjetApi);
  89.         $em->persist($mailjetApi);
  90.         $em->flush();
  91.         return $this->redirectToRoute('app_home');
  92.     }
  93.     #[Route(path'/test-files-aides'name'test-files-aides'methods: ['GET''POST'])]
  94.     public function TestFilesAides(HelpersFirmsService $helpersFirmsService): Response
  95.     {
  96.         return $this->redirectToRoute('app_home');
  97.     }
  98.     #[Route(path'/robots.txt'name'robots'methods: ['GET'])]
  99.     public function robots(): Response
  100.     {
  101.         $response = new Response(
  102.             "User-agent: *\nAllow: /",
  103.             Response::HTTP_OK,
  104.             ['content-type' => 'text/plain']
  105.         );
  106.         return $response;
  107.     }
  108.     #[Route(path'/test'name'test'methods: ['GET''POST'])]
  109.     public function test(StakeholderRepository $stakeholderRepositoryAccountingFirmRepository $accountingFirmRepository): Response
  110.     {
  111.         $stakeholders $stakeholderRepository->findBySubscriptionType(
  112.             $accountingFirmRepository->find(167),
  113.             StakeholderCategory::CUSTOMER_SLUG,
  114.             StakeholderSubscriptionType::NEWSLETTER
  115.         );
  116.         $found array_filter($stakeholders, fn($s) => strtolower($s->getEmail()) === '1mmo.armelleauguste@gmail.com');
  117.         dd(array_values($found));
  118.     }
  119.     #[Route('/nlpreview/{cabinet}'name'app_nlpreview')]
  120.     public function newsletterPreview(AccountingFirm $cabinetMailing $mailingMjmlExtension $mjmlRendererEnvironment $twig): Response
  121.     {
  122.         $templateParams $mailing->getNewsletterCabinetTemplateParams($cabinettrue);
  123.         return new Response($mjmlRenderer->render($twig->render('mjml/newsletter-cabinet-template.mjml'$templateParams)));
  124.     }
  125.     #[Route(path'/get-audio-ausha'name'w_podcast_get_audio_ausha')]
  126.     public function getAudioAusha(Request $request)
  127.     {
  128.         $aushaId $request->query->get('aushaid');
  129.         $aushaToken "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiZjkyM2U5ZmE0NzczYWVlYTE0NThmZWFiYjYzNWE3MWUxYTc5YTM2MmVjMjU3MjFhYTNlMzc4MDg4YWRkMTUyYjU2N2I0NjhjNjQwMmE1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VsZXRlT25lIiwic2hvd3Mud2ViaG9va3MucG9kY2FzdHMiXX0.nnwdeoX3AA7ENvDU1d8IBUo5vYqCCLO3JoqeV7wbBQRTFpuPWsv2-obl64N3C-0jxFnf--VNJFPqbBHbKeaN_rV7147Hkk_f6fFz-2f8VcryokbYobfRoWCjaJCpts1op7xhDCGFh5_VAxU4pANGxx2JVonrg0Sh2abbNPpw4Q_Oc1DCSIkfKVew9xWdlDEcD9DQdgYLOvKQyBl0bUDC2Zr1xBnDGbJKGyFlpoPXxdGSGMiS16YOnfl4Vl08tTvHL_uawmFfJ34Vms4zmhZY3QKVWMH3_o0dib4RQLp3leR0b095XJLtNyp0uvrGcvHOj9GhzdSgdNuLyxXO4HAq5Qboo3xGIha9Ayvm7-xrPJLSTzK85zwOS-lPzQ1adNWuWNaYJZvYmsnwLtnUFogsMuoxa1sy2Fo-HHDmT5-KR2N1eNDvDFHTW0vVJkqnVmseF0d6RUCWp-01g7Yw6GT6QBJ-fN8-9R8MsZcyNa54W1sA7ptas2JHo3oCa_VBO_ku9aq4SLTxyjxKosr6GFxPrJMH2SfRq11VuAvb-mOPKvY5_gqe6Z_aWYbd0XuQ0uHHTtnr01u9xxAnVQdEKUUvha_LBuA9xbTjy8cAmYxgiMf5GYO4jeiikqPXlgRASVPFV6-IREYvMAqQFIDNgXnNLfn1-xbXpBtmR0Bb8IzDLqc";
  130.         $client = new Client(['base_uri' => 'https://developers.ausha.co/v1/podcasts/']);
  131.         $headers = [
  132.             'Authorization' => 'Bearer ' $aushaToken,
  133.             'accept' => 'application/json',
  134.             'content-type' => 'application/json',
  135.         ];
  136.         $ausha_mp3 null;
  137.         try {
  138.             $response $client->request('GET'$aushaId, [
  139.                 'headers' => $headers
  140.             ]);
  141.             dd($response);
  142.             $ausha json_decode($response->getBody()->getContents());
  143.             if ($ausha->data->audio_url) {
  144.                 $ausha_mp3 $ausha->data->audio_url;
  145.             }
  146.         } catch (\Exception $e) {
  147.             dd($e);
  148.         }
  149.         return new JsonResponse([
  150.             'ausha_mp3' => $ausha_mp3
  151.         ]);
  152.     }
  153.     #[IsGranted('ROLE_ADMIN')]
  154.     #[Route(path'/test-chatbot'name'testChatbot'methods: ['GET''POST'])]
  155.     public function testChatbot(): Response
  156.     {
  157.         return $this->render('app/chatbot.html.twig', [
  158.             'controller_name' => 'AppController',
  159.         ]);
  160.     }
  161. }