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

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