src/Controller/ThemesWebsite/Whileresume/Website/EnterprisesController.php line 83

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ThemesWebsite\Whileresume\Website;
  3. use App\Entity\Articles\Articles;
  4. use App\Entity\Core\Agencies;
  5. use App\Entity\Core\AgenciesHasUsers;
  6. use App\Entity\Core\Users;
  7. use App\Entity\Cvs\Shares;
  8. use App\Entity\Pages\Pages;
  9. use App\Form\Core\UsersType;
  10. use App\Security\LoginFormAuthenticator;
  11. use App\Services\Core\RequestData;
  12. use App\Services\N8nWebhook;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Knp\Component\Pager\PaginatorInterface;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  20. use Symfony\Component\HttpFoundation\Cookie;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Component\HttpFoundation\RedirectResponse;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Response;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  27. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  28. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  29. use Symfony\Component\Security\Core\User\UserInterface;
  30. use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;
  31. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  32. use Symfony\Component\Security\Http\Authentication\AuthenticatorManagerInterface;
  33. use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
  34. use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
  35. use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordCredentialsBadge;
  36. use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
  37. use Twig\Environment;
  38. class EnterprisesController extends AbstractController
  39. {
  40.     private $rd;
  41.     private $em;
  42.     private $passwordEncoder;
  43.     private $ms;
  44.     private $us;
  45.     private $authenticator;
  46.     private $userAuthenticator;
  47.     private $paginator;
  48.     private $twig;
  49.     private $n8n;
  50.     public function __construct(RequestData                  $rd,
  51.                                 EntityManagerInterface       $em,
  52.                                 UserPasswordEncoderInterface $passwordEncoder,
  53.                                 \App\Services\Mails          $ms,
  54.                                 \App\Services\Core\Users     $us,
  55.                                 UserAuthenticatorInterface   $userAuthenticator,
  56.                                 LoginFormAuthenticator       $authenticator,
  57.                                 PaginatorInterface           $paginator,
  58.                                 Environment                  $twig,
  59.                                 N8nWebhook                   $n8n,
  60.     ) {
  61.         $this->rd $rd;
  62.         $this->em $em;
  63.         $this->passwordEncoder $passwordEncoder;
  64.         $this->ms $ms;
  65.         $this->authenticator $authenticator;
  66.         $this->userAuthenticator $userAuthenticator;
  67.         $this->us $us;
  68.         $this->paginator $paginator;
  69.         $this->twig $twig;
  70.         $this->n8n $n8n;
  71.     }
  72.     /**
  73.      * Homepage
  74.      * @param Request $request
  75.      * @return Response
  76.      */
  77.     public function homepage(Request $request): Response
  78.     {
  79.         $session $request->getSession();
  80.         $user $this->getUser();
  81.         $locale $request->getLocale();
  82.         $page $this->em->getRepository(Pages::class)->findOneBy(['name' => 'employer','locale' => $locale]);
  83.         $articles $this->em->getRepository(Articles::class)->getArticles(6,$locale);
  84.         $newUser = new Users();
  85.         $newUser->setPremium(false);
  86.         $form $this->createForm(UsersType::class, $newUser);
  87.         $form->handleRequest($request);
  88.         if ($form->isSubmitted() && $form->isValid()) {
  89.             $data $request->request->all();
  90.             $data $data['users'];
  91.             if($data['acceptTerm'] == "1") {
  92.                 if($data['password']['first'] != $data['password']['second']) {
  93.                     if($locale == "fr") {
  94.                         $session->getFlashBag()->add('danger''Votre second mot de passe n\'est pas identique');
  95.                         return $this->redirectToRoute('whileresume_business_fr');
  96.                     }
  97.                     $session->getFlashBag()->add('danger''Your second password is not identical');
  98.                     return $this->redirectToRoute('whileresume_business_en');
  99.                 }
  100.                 $validationResult $this->filterProfessionalEmail($data['email']);
  101.                 if(!$validationResult) {
  102.                     $session->getFlashBag()->add('danger''Veuillez utiliser une adresse email professionnelle');
  103.                     if($locale == "fr") {
  104.                         return $this->redirectToRoute('whileresume_business_fr');
  105.                     }
  106.                     $session->getFlashBag()->add('danger''Please use a professional email address');
  107.                     return $this->redirectToRoute('whileresume_business_en');
  108.                 }
  109.                 $verificationUser $this->em->getRepository(Users::class)->findOneBy(['email' => $data['email']]);
  110.                 if ($verificationUser == null) {
  111.                     $newUser->setVerification(false);
  112.                     $newUser->setTypeAccount("enterprise");
  113.                     $newUser->setFirst(true);
  114.                     $newUser->setEnabled(true);
  115.                     $newUser->setPassword($this->passwordEncoder->encodePassword($newUser,$data['password']['first']));
  116.                     $newUser->setRoles(['ROLE_USER']);
  117.                     $newUser->setUpdatedAt(new \DateTime("now"));
  118.                     $newUser->setCreatedAt(new \DateTime("now"));
  119.                     $this->em->persist($newUser);
  120.                     $this->em->flush();
  121.                     $agency = new Agencies();
  122.                     $agency->setEmail($data['email']);
  123.                     $agency->setFirst(true);
  124.                     $agency->setValide(false);
  125.                     $agency->setPremium(false);
  126.                     $agency->setCreatedAt(new \DateTime("now"));
  127.                     $agency->setUpdatedAt(new \DateTime("now"));
  128.                     $agency->setPourcentCommission(0);
  129.                     $agency->setPourcentCommissionBank(0);
  130.                     $agency->setNoCommission(false);
  131.                     $agency->setCommissionCentimesBank(0);
  132.                     $agency->setLimitedUsers(1);
  133.                     $agency->setLimitedCourses(10);
  134.                     $agency->setLimitedQcm(10);
  135.                     $agency->setLimitedQcmApplication(10);
  136.                     $agency->setMultipleInscription(false);
  137.                     $agency->setStripe(false);
  138.                     $agency->setDemonstration(false);
  139.                     $this->em->persist($agency);
  140.                     $this->em->flush();
  141.                     $newUser->setCurrentAgency($agency);
  142.                     $this->em->persist($newUser);
  143.                     $this->em->flush();
  144.                     $ahu = new AgenciesHasUsers();
  145.                     $ahu->setUser($user);
  146.                     $ahu->setAdmin(true);
  147.                     $ahu->setAgency($agency);
  148.                     $this->em->persist($agency);
  149.                     $this->em->flush();
  150.                     $title "";
  151.                     if($locale == "fr") {
  152.                         $title "Votre profil Whileresume est en cours de vérification";
  153.                     } elseif($locale == "en") {
  154.                         $title "Your Whileresume profile is under review";
  155.                     }
  156.                     $descriptionHTML $this->twig->render("application/whileresume/gestion/emails/"$locale ."/register_recruiter.html.twig",[
  157.                         'title' => $title,
  158.                         'email' => $data['email']
  159.                     ]);
  160.                     $this->ms->webhook($title,$descriptionHTMLnull$data['email'], nullnull);
  161.                     // Notification n8n (non bloquante)
  162.                     $this->n8n->send($_ENV['N8N_WEBHOOK_NOTIF_REGISTER_ENTERPRISE'] ?? null, [
  163.                         'name'         => $newUser->getName(),
  164.                         'lastname'     => $newUser->getLastname(),
  165.                         'city'         => $agency->getCity(),
  166.                         'mobile'       => false,
  167.                         'email'        => $newUser->getEmail(),
  168.                         'id_candidate' => null,
  169.                         'id_user'      => $newUser->getId(),
  170.                     ]);
  171.                     $this->userAuthenticator->authenticateUser(
  172.                         $newUser,
  173.                         $this->authenticator,
  174.                         $request
  175.                     );
  176.                     if($locale == "fr") {
  177.                         return $this->redirectToRoute('locale_cvs_gestion_enterprises_first',['_locale' => $locale]);
  178.                     }
  179.                     return $this->redirectToRoute('cvs_gestion_enterprises_first');
  180.                 }
  181.             }
  182.             if($locale == "fr") {
  183.                 $session->getFlashBag()->add('danger''L\'adresse mail est déjà dans notre base de données');
  184.                 return $this->redirectToRoute('whileresume_business_fr');
  185.             }
  186.             $session->getFlashBag()->add('danger''The email address is already in our database');
  187.             return $this->redirectToRoute('whileresume_business_en');
  188.         }
  189.         return $this->render('application/whileresume/website/business/homepage.html.twig',[
  190.             'page' => $page,
  191.             'articles' => $articles,
  192.             'form' => $form->createView(),
  193.         ]);
  194.     }
  195.     private function filterProfessionalEmail($email) {
  196.         // Validation basique du format email
  197.         if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
  198.             return [
  199.                 'success' => false,
  200.                 'message' => 'Format d\'email invalide'
  201.             ];
  202.         }
  203.         // Domaines personnels interdits
  204.         $forbiddenDomains = [
  205.             'gmail.com''yahoo.com''yahoo.fr''hotmail.com''hotmail.fr',
  206.             'outlook.com''outlook.fr''live.com''live.fr''aol.com',
  207.             'free.fr''orange.fr''wanadoo.fr''laposte.net''sfr.fr',
  208.             'bbox.fr''icloud.com''me.com''protonmail.com''tutanota.com'
  209.         ];
  210.         // Domaines temporaires interdits
  211.         $tempDomains = [
  212.             'tempmail.org''10minutemail.com''guerrillamail.com',
  213.             'mailinator.com''yopmail.com'
  214.         ];
  215.         // Extraction du domaine
  216.         $emailParts explode('@'$email);
  217.         if (count($emailParts) !== 2) {
  218.             return false;
  219.         }
  220.         $domain strtolower(trim($emailParts[1]));
  221.         // Vérification des domaines interdits
  222.         if (in_array($domain$forbiddenDomains)) {
  223.             return false;
  224.         }
  225.         // Vérification des domaines temporaires
  226.         if (in_array($domain$tempDomains)) {
  227.             return false;
  228.         }
  229.         // Vérification basique du domaine
  230.         if (strlen($domain) < || !strpos($domain'.')) {
  231.             return false;
  232.         }
  233.         return true;
  234.     }
  235. }