<?phpnamespace App\Controller\ThemesWebsite\Whileresume\Website;use App\Entity\Articles\Articles;use App\Entity\Core\Agencies;use App\Entity\Core\Users;use App\Entity\Cvs\Shares;use App\Entity\Pages\Pages;use App\Form\Core\UsersType;use App\Security\LoginFormAuthenticator;use App\Services\Core\RequestData;use Doctrine\ORM\EntityManagerInterface;use Knp\Component\Pager\PaginatorInterface;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\EventDispatcher\EventDispatcherInterface;use Symfony\Component\HttpFoundation\Cookie;use Symfony\Component\HttpFoundation\JsonResponse;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;use Symfony\Component\Security\Http\Authentication\AuthenticatorManagerInterface;use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordCredentialsBadge;use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;use Twig\Environment;class EnterprisesController extends AbstractController{ private $rd; private $em; private $passwordEncoder; private $ms; private $us; private $authenticator; private $userAuthenticator; private $paginator; private $twig; public function __construct(RequestData $rd, EntityManagerInterface $em, UserPasswordEncoderInterface $passwordEncoder, \App\Services\Mails $ms, \App\Services\Core\Users $us, UserAuthenticatorInterface $userAuthenticator, LoginFormAuthenticator $authenticator, PaginatorInterface $paginator, Environment $twig, ) { $this->rd = $rd; $this->em = $em; $this->passwordEncoder = $passwordEncoder; $this->ms = $ms; $this->authenticator = $authenticator; $this->userAuthenticator = $userAuthenticator; $this->us = $us; $this->paginator = $paginator; $this->twig = $twig; } /** * Homepage * @param Request $request * @return Response */ public function homepage(Request $request): Response { $session = $request->getSession(); $user = $this->getUser(); $locale = $request->getLocale(); $page = $this->em->getRepository(Pages::class)->findOneBy(['name' => 'employer','locale' => $locale]); $articles = $this->em->getRepository(Articles::class)->getArticles(6,$locale); $newUser = new Users(); $newUser->setPremium(false); $form = $this->createForm(UsersType::class, $newUser); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $request->request->all(); $data = $data['users']; if($data['acceptTerm'] == "1") { if($data['password']['first'] != $data['password']['second']) { if($locale == "fr") { $session->getFlashBag()->add('danger', 'Votre second mot de passe n\'est pas identique'); return $this->redirectToRoute('whileresume_business_fr'); } $session->getFlashBag()->add('danger', 'Your second password is not identical'); return $this->redirectToRoute('whileresume_business_en'); } $validationResult = $this->filterProfessionalEmail($data['email']); if(!$validationResult) { $session->getFlashBag()->add('danger', 'Veuillez utiliser une adresse email professionnelle'); if($locale == "fr") { return $this->redirectToRoute('whileresume_business_fr'); } $session->getFlashBag()->add('danger', 'Please use a professional email address'); return $this->redirectToRoute('whileresume_business_en'); } $verificationUser = $this->em->getRepository(Users::class)->findOneBy(['email' => $data['email']]); if ($verificationUser == null) { $newUser->setVerification(false); $newUser->setTypeAccount("enterprise"); $newUser->setFirst(true); $newUser->setEnabled(true); $newUser->setPassword($this->passwordEncoder->encodePassword($newUser,$data['password']['first'])); $newUser->setRoles(['ROLE_USER']); $newUser->setUpdatedAt(new \DateTime("now")); $newUser->setCreatedAt(new \DateTime("now")); $this->em->persist($newUser); $this->em->flush(); $agency = new Agencies(); $agency->setEmail($data['email']); $agency->setFirst(true); $agency->setValide(false); $agency->setPremium(false); $agency->setCreatedAt(new \DateTime("now")); $agency->setUpdatedAt(new \DateTime("now")); $agency->setPourcentCommission(0); $agency->setPourcentCommissionBank(0); $agency->setNoCommission(false); $agency->setCommissionCentimesBank(0); $agency->setLimitedUsers(1); $agency->setLimitedCourses(10); $agency->setLimitedQcm(10); $agency->setLimitedQcmApplication(10); $agency->setMultipleInscription(false); $agency->setStripe(false); $agency->setDemonstration(false); $this->em->persist($agency); $this->em->flush(); $newUser->setCurrentAgency($agency); $this->em->persist($newUser); $this->em->flush(); $title = ""; if($locale == "fr") { $title = "Bienvenue sur Whileresume - Votre compte est activée"; } elseif($locale == "en") { $title = "Welcome to Whileresume - Your account is activated"; } $descriptionHTML = $this->twig->render("application/whileresume/gestion/emails/". $locale ."/register_recruiter.html.twig",[ 'title' => $title, 'email' => $data['email'] ]); $this->ms->webhook($title,$descriptionHTML, null, $data['email'], null, null); $this->userAuthenticator->authenticateUser( $newUser, $this->authenticator, $request ); return $this->redirectToRoute('customer_homepage'); } } if($locale == "fr") { $session->getFlashBag()->add('danger', 'L\'adresse mail est déjà dans notre base de données'); return $this->redirectToRoute('whileresume_business_fr'); } $session->getFlashBag()->add('danger', 'The email address is already in our database'); return $this->redirectToRoute('whileresume_business_en'); } return $this->render('application/whileresume/website/business/homepage_'.$locale.'.html.twig',[ 'page' => $page, 'articles' => $articles, 'form' => $form->createView(), ]); } private function filterProfessionalEmail($email) { // Validation basique du format email if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return [ 'success' => false, 'message' => 'Format d\'email invalide' ]; } // Domaines personnels interdits $forbiddenDomains = [ 'gmail.com', 'yahoo.com', 'yahoo.fr', 'hotmail.com', 'hotmail.fr', 'outlook.com', 'outlook.fr', 'live.com', 'live.fr', 'aol.com', 'free.fr', 'orange.fr', 'wanadoo.fr', 'laposte.net', 'sfr.fr', 'bbox.fr', 'icloud.com', 'me.com', 'protonmail.com', 'tutanota.com' ]; // Domaines temporaires interdits $tempDomains = [ 'tempmail.org', '10minutemail.com', 'guerrillamail.com', 'mailinator.com', 'yopmail.com' ]; // Extraction du domaine $emailParts = explode('@', $email); if (count($emailParts) !== 2) { return false; } $domain = strtolower(trim($emailParts[1])); // Vérification des domaines interdits if (in_array($domain, $forbiddenDomains)) { return false; } // Vérification des domaines temporaires if (in_array($domain, $tempDomains)) { return false; } // Vérification basique du domaine if (strlen($domain) < 4 || !strpos($domain, '.')) { return false; } return true; }}