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

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