src/Controller/WidgetTousEnLigneController.php line 115

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\EmailBlacklist;
  4. use App\Entity\TousEnLigneContact;
  5. use App\Repository\AccountingFirmRepository;
  6. use App\Repository\AuthorizedDomainRepository;
  7. use App\Services\WidgetMailing;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Qferrer\Mjml\Twig\MjmlExtension;
  10. use Response;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  16. use Symfony\Component\Mailer\MailerInterface;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Twig\Environment;
  19. class WidgetTousEnLigneController extends AbstractController
  20. {
  21.   protected MjmlExtension $mjmlRenderer;
  22.   protected Environment $twig;
  23.   public function __construct(MailerInterface $mailerMjmlExtension $mjmlRendererEnvironment $twig)
  24.     {
  25.         $this->mjmlRenderer $mjmlRenderer;
  26.         $this->twig $twig;
  27.     }
  28.   #[Route('/check-tous-en-ligne'name'w_tous_en_ligne_check')]
  29.   public function ctrl_checkTousEnLigne(Request $requestAccountingFirmRepository $repositorystring $prefix null): JsonResponse
  30.   {
  31.     $token $request->query->get('token');
  32.     $host $request->get('host');
  33.     if ($token && $host) {
  34.       $accountingFirm $repository->findOneBy(['tousEnLigneToken' => $token]);
  35.       $isAuthorized false;
  36.       if ($accountingFirm && in_array($host$accountingFirm->getListAuthorizedDomains())) {
  37.         $isAuthorized true;
  38.       }
  39.       $url $isAuthorized $accountingFirm->getTousEnLigneWidgetUrl() : null;
  40.     } else {
  41.       $accountingFirm $repository->findOneBy(['host' => $host]);
  42.       $url $accountingFirm $prefix $this->generateUrl('w_tous_en_ligne_get') : null;
  43.     }
  44.     return $this->json($url);
  45.   }
  46.   #[Route('/widget-tous-en-ligne'name'w_tous_en_ligne_get')]
  47.   public function ctrl_widgetTousEnLigne(Request $requestAccountingFirmRepository $repositoryAuthorizedDomainRepository $domains)
  48.   {
  49.     $token $request->query->get('token');
  50.     $host $request->get('host');
  51.     if ($host != "preview") {
  52.       $accountingFirm $repository->findOneBy(['host' => $host]);
  53.       if (is_null($accountingFirm)) {
  54.         $domains $domains->findBy(['name' => $host]);
  55.         if (is_null($domains)) {
  56.           throw new NotFoundHttpException();
  57.         }
  58.         foreach ($domains as $dom) {
  59.           $tmp_ac $dom->getAccountingFirm();
  60.           if ($tmp_ac->getTousEnLigneToken() == $token) {
  61.             $accountingFirm $tmp_ac;
  62.             break;
  63.           }
  64.         }
  65.       }
  66.       if (is_null($accountingFirm)) {
  67.         throw new NotFoundHttpException();
  68.       }
  69.     }
  70.     return $this->render('widget_tous_en_ligne/content.html.twig', [
  71.       'cabinet' => $accountingFirm,
  72.     ]);
  73.   }
  74.   #[Route('/embed'name'w_tous_en_ligne_embed')]
  75.   public function embed()
  76.   {
  77.     $root $this->getParameter('kernel.project_dir');
  78.     $path $root '/public/widgets/widget_tous_en_ligne/widget_tous_en_ligne.js';
  79.     return new BinaryFileResponse($path);
  80.   }
  81.   #[Route('/{filename}.{format}'name'w_tous_en_ligne_files')]
  82.   public function tous_en_ligne_files(string $filenamestring $format)
  83.   {
  84.       $allowed = array('png''jpg''jpeg''gif''js''svg''eot''ttf''woff');
  85.       if (in_array($format$allowed)) {
  86.           $root $this->getParameter('kernel.project_dir');
  87.           $path $root '/public/widget_tous_en_ligne/' $filename '.' $format;
  88.           if (!file_exists($path)) {
  89.             $path $root '/public/widgets/widget_tous_en_ligne/' $filename '.' $format;
  90.           }
  91.           return new BinaryFileResponse($path);
  92.       }
  93.       return false;
  94.   }
  95.   //si formulaire présent dans le widget, sinon supprimé
  96.   #[Route('/send'name'tous_en_ligne_send_form')]
  97.   public function tous_en_ligne_send(Request $requestEntityManagerInterface $emAccountingFirmRepository $accountingFirmRepositoryWidgetMailing $mailing)
  98.   {
  99.     $prenom $request->get('prenom');
  100.     $nom $request->get('nom');
  101.     $email $request->get('email');
  102.     $tel $request->get('phone');
  103.     $nameCompany $request->get('nameCompany');
  104.     $siret $request->get('siret');
  105.     $fonction $request->get('fonction');
  106.     $emailDirigeant $request->get('emailDirigeant');
  107.     $address $request->get('address');
  108.     $code_postal $request->get('code_postal');
  109.     $ville $request->get('ville');
  110.     $secteur $request->get('secteur');
  111.     $taille $request->get('taille');
  112.     $siteInternet $request->get('siteInternet');
  113.     $taille $request->get('taille');
  114.     $outilsUsed explode(";"$request->get('outilsUsed'));
  115.     $outilsWant explode(";"$request->get('outilsWant'));
  116.     $idCabinet $request->get('cabinet');
  117.     $cabinet $accountingFirmRepository->findById($idCabinet);
  118.     // return new JsonResponse([$prenom,$nom,$email,$tel,$nameCompany,$siret,$fonction,$address,$code_postal, $ville]);
  119.     if (!empty($prenom) && !empty($nom) && !empty($email) && !empty($tel) && !empty($nameCompany) && !empty($siret) && !empty($fonction) && !empty($address) && !empty($code_postal) && !empty($ville)) {
  120.       // Vérifier si l'email est dans la blacklist
  121.       $blacklistRepo $em->getRepository(EmailBlacklist::class);
  122.       if ($blacklistRepo->isEmailBlacklisted($email)) {
  123.         // Incrémenter le compteur de tentatives
  124.         $blacklistedEmail $blacklistRepo->findByEmail($email);
  125.         if ($blacklistedEmail) {
  126.           $blacklistedEmail->incrementBlockCount();
  127.           $em->persist($blacklistedEmail);
  128.           $em->flush();
  129.         }
  130.         return new JsonResponse(['status' => 'error''message' => 'Votre email est dans notre liste noire. Impossible d\'envoyer la demande.'], 403);
  131.       }
  132.       $widgetNameContact = new TousEnLigneContact;
  133.       $widgetNameContact->setPrenom($prenom);
  134.       $widgetNameContact->setNom($nom);
  135.       $widgetNameContact->setPhone($tel);
  136.       $widgetNameContact->setEmail($email);
  137.       $widgetNameContact->setNameCompany($nameCompany);
  138.       $widgetNameContact->setSiret($siret);
  139.       $widgetNameContact->setFonction($fonction);
  140.       if (!empty($emailDirigeant)) {
  141.         $widgetNameContact->setEmailDirigeant($emailDirigeant);
  142.       }
  143.       $widgetNameContact->setAddress($address);
  144.       $widgetNameContact->setCodePostal($code_postal);
  145.       $widgetNameContact->setVille($ville);
  146.       $widgetNameContact->setSecteur($secteur);
  147.       $widgetNameContact->setTaille($taille);
  148.       if ($siteInternet == "true") {
  149.         $widgetNameContact->setSiteInternet(true);
  150.       } else {
  151.         $widgetNameContact->setSiteInternet(false);
  152.       }
  153.       $widgetNameContact->setOutilsUsed($outilsUsed);
  154.       $widgetNameContact->setOutilsWant($outilsWant);
  155.       $widgetNameContact->setCabinet($cabinet);
  156.       $widgetNameContact->updateTimestamps();
  157.       $em->persist($widgetNameContact);
  158.       $em->flush();
  159.       $data = [
  160.         'name' => $nom,
  161.         'prenom' => $prenom,
  162.         'email' => $email,
  163.         'tel' => $tel,
  164.         'nameCompany' => $nameCompany,
  165.         'siret' => $siret,
  166.         'fonction' => $fonction,
  167.         'emailDirigeant' => $emailDirigeant,
  168.         'address' => $address,
  169.         'code_postal' => $code_postal,
  170.         'ville' => $ville,
  171.         'secteur' => $secteur,
  172.         'taille' => $taille,
  173.         'siteInternet' => $siteInternet,
  174.         'outilsUsed' => $outilsUsed,
  175.         'outilsWant' => $outilsWant,
  176.         'nameExpert' => "Camille",
  177.         'emailExpert' => "camille@lesfoliweb.fr",
  178.     ];
  179.       // send mail exemple
  180.       $mailing->sendTelAgence($cabinet$data);
  181.       $mailing->sendTelClient($cabinet$data);
  182.       $mailing->sendTelExpert($cabinet$data);
  183.       $mailing->sendTelCabinet($cabinet$data);
  184.       return new JsonResponse('success');
  185.     }
  186.     return new JsonResponse('error');
  187.   }
  188. }