src/Controller/SecurityController.php line 154

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\SiteUser;
  4. use App\Entity\Users;
  5. use App\Form\OtpChekType;
  6. use App\Form\ProfilFormType;
  7. use App\Form\SecurityType;
  8. use App\Form\SiteUserType;
  9. use App\Form\UpdatePasswordType;
  10. use App\Form\UserIscriptionType;
  11. use App\Service\OtpCodeHandler;
  12. use App\Service\SendNotificationService;
  13. use App\Service\Verify\TwilioService;
  14. use App\Utils\LogManager;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use Doctrine\Persistence\ManagerRegistry;
  17. use Exception;
  18. use phpDocumentor\Reflection\Types\This;
  19. use Psr\Log\LoggerInterface;
  20. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  22. use Symfony\Component\HttpFoundation\JsonResponse;
  23. use Symfony\Component\HttpFoundation\RedirectResponse;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  27. use Symfony\Component\Mailer\MailerInterface;
  28. use Symfony\Component\Mime\Email;
  29. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  30. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  31. use Symfony\Component\Security\Core\User\UserInterface;
  32. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  33. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  34. use Symfony\Component\Uid\Uuid;
  35. use Symfony\Contracts\HttpClient\HttpClientInterface;
  36. use Twig\Environment;
  37. class SecurityController extends AbstractController
  38. {
  39.     private const MAX_ATTEMPTS 3;
  40.     private const BLOCKED_DURATION 600;
  41.     private EntityManagerInterface $em;
  42.     private LoggerInterface $logger;
  43.     private HttpClientInterface $client;
  44.     private MailerInterface $mailer;
  45.     private $twig;
  46.     private OtpCodeHandler $otpCodeHandler;
  47.     private ManagerRegistry $registry;
  48.     private SendNotificationService $sendNotificationService;
  49.     private TwilioService $twilioService;
  50.     public function __construct(
  51.         HttpClientInterface     $client,
  52.         EntityManagerInterface  $em,
  53.         LoggerInterface         $logger,
  54.         MailerInterface         $mailer,
  55.         Environment             $twig,
  56.         OtpCodeHandler          $otpCodeHandler,
  57.         SendNotificationService $sendNotificationService,
  58.         ManagerRegistry         $registry,
  59.         TwilioService           $twilioService
  60.     )
  61.     {
  62.         $this->em $em;
  63.         $this->logger $logger;
  64.         $this->mailer $mailer;
  65.         $this->twig $twig;
  66.         $this->client $client;
  67.         $this->otpCodeHandler $otpCodeHandler;
  68.         $this->sendNotificationService $sendNotificationService;
  69.         $this->registry $registry;
  70.         $this->twilioService $twilioService;
  71.     }
  72.     public function login(AuthenticationUtils $authenticationUtils): Response
  73.     {
  74.         // get the login error if there is one
  75.         $error $authenticationUtils->getLastAuthenticationError();
  76.         // last username entered by the user
  77.         $lastUsername $authenticationUtils->getLastUsername();
  78.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  79.     }
  80.     public function logoutCustom(Request $requestTokenStorageInterface $tokenStorage): RedirectResponse
  81.     {
  82.         LogManager::save("inconnu""Déconnexion réussie");
  83.         if ($this->getUser() instanceof UserInterface) {
  84.             // Déconnectez l'utilisateur en supprimant le token
  85.             $tokenStorage->setToken(null);
  86.         }
  87.         return $this->redirectToRoute('app_user_logout');
  88.     }
  89.     public function logout(Request $requestTokenStorageInterface $tokenStorage)
  90.     {
  91.         LogManager::save("inconnu""Déconnexion réussie");
  92.         if ($this->getUser() instanceof UserInterface) {
  93.             // Déconnectez l'utilisateur en supprimant le token
  94.             $tokenStorage->setToken(null);
  95.         }
  96.         return $this->redirectToRoute('homepage');
  97.     }
  98.     public function resetPassword(): Response
  99.     {
  100.         return $this->render('security/reset_password.html.twig', array(
  101.             'form' => '',
  102.         ));
  103.     }
  104.     public function genOtp()
  105.     {
  106.         $n 6;
  107.         $generator "1357902468";
  108.         $result "";
  109.         for ($i 1$i <= $n$i++) {
  110.             $result .= substr($generator, (rand() % (strlen($generator))), 1);
  111.         }
  112.         return $result;
  113.     }
  114.     public function sendSMS($otp$phoneNumber)
  115.     {
  116.         $response "KO";
  117.         try {
  118.             $response $this->client->request('GET''https://api.budgetsms.net/sendsms/', [
  119.                 // these values are automatically encoded before including them in the URL
  120.                 'query' => [
  121.                     'username' => 'papove01',
  122.                     'userid' => '18671',
  123.                     'handle' => '3b699dc89c88cd862044fab30349a14b',
  124.                     'msg' => 'Bienvenue sur TownSys! Votre code de confirmation est: ' $otp,
  125.                     'from' => 'TownSys',
  126.                     'to' => $phoneNumber,
  127.                 ],
  128.             ]);
  129.             return $response;
  130.         } catch (Exception $e) {
  131.             $this->logger->info('>>>>>>>>>', ["------------------------------------------------"]);
  132.             $this->logger->info('SMS sending Exception', [$e->getMessage()]);
  133.             return $response;
  134.         }
  135.     }
  136.     public function inscriptionBis(Request $requestUserPasswordHasherInterface $passwordHasherMailerInterface $mailer): Response
  137.     {
  138.         $user = new Users();
  139.         $form $this->createForm(UserIscriptionType::class, $user);
  140.         $form->handleRequest($request);
  141.         if ($form->isSubmitted() && $form->isValid()) {
  142.             $verificationMode $form->get('verificationMode')->getData();
  143.             $userMail $user->getMail();
  144.             $user->setPassword(
  145.                 $passwordHasher->hashPassword(
  146.                     $user,
  147.                     $form->get('password')->getData()
  148.                 )
  149.             );
  150.             $user->setFirstLogin(true);
  151.             $otp $this->genOtp();
  152.             $user->setUserType(4);
  153.             $user->setIsAuthority(false);
  154.             $user->setOtp($otp);
  155.             $user->setStatus(0);
  156.             $user->setTimeOtp((new \DateTime())->add(new \DateInterval('P3M')));
  157.             $user->setUID(Uuid::v3(
  158.                 Uuid::fromString(Uuid::NAMESPACE_OID),
  159.                 $user->getMail() ?? uniqid()));
  160.             $em $this->registry->getManager();
  161.             $em->persist($user);
  162.             $em->flush();
  163.             // ajouter le symbole + devant le numéro de téléphone
  164.             $phoneNumber $user->getTelephone();
  165.             try {
  166.                 if ($verificationMode == "sms") {
  167.                     if (substr($phoneNumber01) != "+") {
  168.                         $phoneNumber "+" $phoneNumber;
  169.                     }
  170.                     $verification $this->twilioService->startVerification($phoneNumber$verificationMode);
  171.                     $this->logger->info('REPONSE API SMS', ["----------------------------------------------------------------------------------------------------------------"]);
  172.                     $this->logger->info('reponse sms', [$verification]);
  173.                     if (!$verification->isValid()) {
  174.                         $em->remove($user);
  175.                         // put the errors array in the flash message
  176.                         $this->addFlash('user_inscription_fail'$verification->getErrors());
  177.                         return $this->redirectToRoute('app_user_inscription');
  178.                     }
  179.                 } else {
  180.                     $emailTemplate = (new TemplatedEmail())
  181.                         ->from($this->getParameter('mailFrom'))
  182.                         ->to($userMail)
  183.                         ->subject('Confirmation Inscription sur MOKANDA')
  184.                         ->text('inscription effectué avec succès!')
  185.                         ->htmlTemplate('email/verification_code_email.html.twig')
  186.                         ->context([
  187.                             'user' => $user,
  188.                             'otp' => $otp
  189.                         ]);
  190.                     $mailer->send($emailTemplate);
  191.                     $this->addFlash('message''le message a été envoyé');
  192.                     $this->logger->info('After send mail code', []);
  193.                 }
  194.                 $otpData = [
  195.                     'verificationMode' => $verificationMode,
  196.                     'user' => $user,
  197.                     'attempts' => 1,
  198.                 ];
  199.                 $key "otpData_" $user->getId();
  200.                 $request->getSession()->set($key$otpData);
  201.                 $request->getSession()->set('user_phone'$phoneNumber);
  202.                 $request->getSession()->set('user_mail'$userMail);
  203.             } catch (Exception $e) {
  204.                 //throw $th;
  205.                 $this->logger->info('In Exception', [$e->getMessage()]);
  206.                 $this->addFlash('user_inscription_fail''Une erreur est survenur lors de l\'inscription, prière véfifier vorte connexion');
  207.                 return $this->redirectToRoute('app_user_inscription');
  208.             } catch (TransportExceptionInterface $e) {
  209.                 $this->logger->info('In Exception transport', [$e->getMessage()]);
  210.                 // some error prevented the email sending; display an
  211.                 // error message or try to resend the message
  212.                 $this->addFlash('user_inscription_fail''Une erreur est survenur lors de l\'inscription, prière contactez le support');
  213.                 return $this->redirectToRoute('app_user_inscription');
  214.             }
  215.             $this->addFlash('user_inscription_success''Votre compte utilisateur a été créé avec succès, prière de vous connceter!');
  216.             return $this->redirectToRoute('app_user_otp_check', ['user_id' => $user->getUID()]);
  217.         }
  218.         return $this->render('security/inscription.html.twig', [
  219.             'form' => $form->createView(),
  220.         ]);
  221.     }
  222.     public function inscription(Request $requestUserPasswordHasherInterface $passwordHasherMailerInterface $mailer): Response
  223.     {
  224.         $user = new Users();
  225.         $form $this->createForm(UserIscriptionType::class, $user);
  226.         $form->handleRequest($request);
  227.         $verificationMode null;
  228.         if ($form->isSubmitted() && $form->isValid()) {
  229.             $verificationMode $form->get('verificationMode')->getData();
  230.             $request->getSession()->set('verificationMode'$verificationMode);
  231.             $userMail $user->getMail();
  232.             $user->setPassword(
  233.                 $passwordHasher->hashPassword(
  234.                     $user,
  235.                     $form->get('password')->getData()
  236.                 )
  237.             );
  238.             $user->setFirstLogin(true);
  239.             $otp $this->genOtp();
  240.             $user->setUserType(4);
  241.             $user->setIsAuthority(false);
  242.             $user->setOtp($otp);
  243.             $user->setStatus(0);
  244.             $user->setTimeOtp((new \DateTime())->add(new \DateInterval('P3M')));
  245.             $em $this->registry->getManager();
  246.             $em->persist($user);
  247.             $em->flush();
  248.             // do anything else you need here, like send an email
  249.             try {
  250.                 if ($verificationMode == "sms") {
  251.                     $response $this->sendSMS($otp$user->getTelephone());
  252.                     $this->logger->info('REPONSE API SMS', ["----------------------------------------------------------------------------------------------------------------"]);
  253.                     $this->logger->info('reponse sms', [$response]);
  254.                 } else {
  255. //                    $email = (new Email())
  256. //                        ->from('[email protected]')
  257. //                        ->to($user->getMail())
  258. //                        //->to( '' )
  259. //                        ->subject('Confirmation Inscription sur MOKANDA')
  260. //                        ->text('inscription effectué avec succès!')
  261. //                        ->html('<p> Cher, ' . $userMail . " Nous avons reçu votre demande d'inscription sur la plateforme MOKANDA-RDC www.mokanda-rdc.com , voici votre code de confirmation: " . $otp . '</p>');
  262. //
  263. //                    $mailer->send($email);
  264.                     // Envoyer un mail de réponse à l'internaute
  265.                     $emailTemplate = (new TemplatedEmail())
  266.                         ->from($this->getParameter('mailFrom'))
  267.                         ->to($userMail)
  268.                         ->subject('Confirmation Inscription sur MOKANDA')
  269.                         ->text('inscription effectué avec succès!')
  270.                         ->htmlTemplate('email/verification_code_email.html.twig')
  271.                         ->context([
  272.                             'user' => $user,
  273.                             'otp' => $otp
  274.                         ]);
  275.                     $mailer->send($emailTemplate);
  276.                     $this->addFlash('message''le message a été envoyé');
  277.                     $this->logger->info('After send mail code', []);
  278.                 }
  279.                 $otpData = [
  280.                     'verificationMode' => $verificationMode,
  281.                     'user' => $user,
  282.                     'attempts' => 1
  283.                 ];
  284.                 $key "otpData_" $user->getId();
  285.                 $request->getSession()->set($key$otpData);
  286.             } catch (Exception $e) {
  287.                 //throw $th;
  288.                 $this->logger->info('In Exception', [$e->getMessage()]);
  289.                 $this->addFlash('user_inscription_fail''Une erreur est survenur lors de l\'inscription, prière véfifier vorte connexion');
  290.                 return $this->redirectToRoute('app_user_inscription');
  291.             } catch (TransportExceptionInterface $e) {
  292.                 $this->logger->info('In Exception transport', [$e->getMessage()]);
  293.                 // some error prevented the email sending; display an
  294.                 // error message or try to resend the message
  295.                 $this->addFlash('user_inscription_fail''Une erreur est survenur lors de l\'inscription, prière contactez le support');
  296.                 return $this->redirectToRoute('app_user_inscription');
  297.             }
  298.             $this->addFlash('user_inscription_success''Votre compte utilisateur a été créé avec succès, prière de vous connceter!');
  299.             return $this->redirectToRoute('app_user_otp_check', ['user_id' => $user->getId()]);
  300.         }
  301.         return $this->render('security/inscription.html.twig', [
  302.             'form' => $form->createView(),
  303.         ]);
  304.     }
  305.     public function resendOtpCode(Users $userRequest $request)
  306.     {
  307.         $formOtp $this->createForm(OtpChekType::class);
  308.         $formOtp->handleRequest($request);
  309.         $id $user->getId();
  310.         $key 'otpData_' $id;
  311.         $otpData $request->getSession()->get($key);
  312.         try {
  313.             if ($otpData >= 3) {
  314.                 throw new Exception("Vous avez atteint le nombre maximun des tentatives d'envoi de code otp");
  315.             }
  316.             $this->otpCodeHandler->sendCode($user);
  317.             $this->addFlash('message''le message a été envoyé');
  318.             $this->logger->info('After send mail code', []);
  319.             $this->addFlash('send_code_success''Un nouveau code vous a été renvoyé');
  320.         } catch (Exception|TransportExceptionInterface $e) {
  321.             $this->logger->info('In Exception transport', [$e->getMessage()]);
  322.             $this->addFlash('send_code_error'$e->getMessage());
  323.         }
  324.         return $this->render(
  325.             'security/otp_verification.html.twig',
  326.             [
  327.                 'formOtp' => $formOtp->createView(),
  328.                 'user' => $user
  329.             ]
  330.         );
  331.     }
  332.     /**
  333.      * @param Request $request
  334.      * @param MailerInterface $mailer
  335.      * @return RedirectResponse
  336.      */
  337.     public function resendOtpCodeBis(Request $requestMailerInterface $mailer): RedirectResponse
  338.     {
  339.         $uID $request->attributes->get('user');
  340.         $user $this->registry->getRepository(Users::class)->findOneBy(['uID' => $uID]);
  341.         if (!$user) {
  342.             throw $this->createNotFoundException(
  343.                 'No user found for id ' $uID
  344.             );
  345.         }
  346.         $key 'otpData_' $user->getId();
  347.         $otpData $request->getSession()->get($key);
  348.         if (!$otpData) {
  349.             return $this->redirectToRoute('app_403_page');
  350.         }
  351.         $verificationMode $otpData['verificationMode'];
  352.         if ($verificationMode == 'sms') {
  353.             $verify $this->twilioService->startVerification($user->getTelephone(), $verificationMode);
  354.             if (!$verify->isValid()) {
  355.                 $this->addFlash('send_code_error'$verify->getErrors());
  356.             } else {
  357.                 $this->addFlash('send_code_success''Un nouveau code vous a été renvoyé');
  358.             }
  359.             return $this->redirectToRoute('app_user_otp_check', ['user_id' => $uID]);
  360.         } else {
  361.             $otp $this->genOtp();
  362.             $user->setOtp($otp);
  363.             $user->setStatus(0);
  364.             $user->setTimeOtp((new \DateTime())->add(new \DateInterval('P3M')));
  365.             $em $this->registry->getManager();
  366.             $em->persist($user);
  367.             $em->flush();
  368.             try {
  369.                 if ($otpData['attempts'] > 3) {
  370.                     $otpData['attempts'] = 0;
  371.                     $key "otpData_" $user->getId();
  372.                     $request->getSession()->set($key$otpData);
  373.                     $this->addFlash('send_code_error''Vous avez atteint le nombre maximun des tentatives d\'envoi de code otp réssayez plus tard');
  374.                 } else {
  375.                     $email = (new Email())
  376.                         ->from($this->getParameter('mailFrom'))
  377.                         ->to($user->getMail())
  378.                         ->subject('Verification Compte Utilisateur')
  379.                         ->text('Vérification de vôtre compte utilisateur')
  380.                         ->html('<p> Cher, ' $user->getMail() . "<br> Nous avons reçu votre demande d'inscription sur la plateforme MOKANDA-RDC www.mokanda-rdc.com , voici votre code de confirmation: " $otp '</p>');
  381.                     $mailer->send($email);
  382.                     $otpData['attempts'] += 1;
  383.                     $request->getSession()->set($key$otpData);
  384.                     $this->addFlash('send_code_success''Un nouveau code vous a été renvoyé');
  385.                 }
  386.                 return $this->redirectToRoute('app_user_otp_check', ['user_id' => $user->getUID()]);
  387.             } catch (TransportExceptionInterface $e) {
  388.                 $this->logger->info('In Exception transport', [$e->getMessage()]);
  389.                 $this->addFlash('user_inscription_fail''Une erreur est survenue lors de l\'inscription, prière contactez le support');
  390.                 return $this->redirectToRoute('app_user_inscription');
  391.             }
  392.         }
  393.     }
  394.     public function otpCheckBis(Request $request)
  395.     {
  396.         $userPhone $request->getSession()->get('user_phone');
  397.         $user $this->registry->getRepository(Users::class)->findOneBy([
  398.             'uID' => $request->get('user_id'),
  399.             'isDeleted' => false,
  400.         ]);
  401.         if (!$user) {
  402.             return $this->redirectToRoute('app_403_page');
  403.         }
  404.         // check if optData is in session if not redirect to 403 page
  405.         $otpData $request->getSession()->get('otpData_' $user->getId());
  406.         if (!$otpData) {
  407.             return $this->redirectToRoute('app_403_page');
  408.         }
  409.         $formOtp $this->createForm(OtpChekType::class);
  410.         $formOtp->handleRequest($request);
  411.         if ($formOtp->isSubmitted() && $formOtp->isValid()) {
  412.             $otpParam $formOtp->get('otp')->getData();
  413.             // selon le mode de vérification on vérifie le code otp
  414.             if ($otpData["verificationMode"] == "sms") {
  415.                 $verify $this->twilioService->checkVerification($userPhone$otpParam);
  416.                 $this->logger->info('REPONSE API SMS', ["----------------------------------------------------------------------------------------------------------------"]);
  417.                 $this->logger->info('reponse sms', [$verify]);
  418.                 if ($verify->isValid()) {
  419.                     $user->setStatus(1);
  420.                     $entityManager $this->registry->getManager();
  421.                     $entityManager->persist($user);
  422.                     $entityManager->flush();
  423.                     $this->addFlash('otp_chek_succed''Votre compte utilisateur a été vérifié avec succès, vous pouvez vous connecter!');
  424.                     return $this->redirectToRoute('app_user_login');
  425.                 } else {
  426.                     $this->addFlash('otp_chek_fail''votre code otp est incorrect ou a expiré!!');
  427.                 }
  428.             } else {
  429.                 if ($otpParam != $user->getOtp()) {
  430.                     $this->logger->info('Mauvais OTP', [$otpParam]);
  431.                     $this->addFlash('otp_chek_fail''votre code otp est incorrect ou a expiré!!');
  432.                 } else {
  433.                     $user->setStatus(1);
  434.                     $entityManager $this->registry->getManager();
  435.                     $entityManager->persist($user);
  436.                     $entityManager->flush();
  437.                     $this->addFlash('otp_chek_succed''Votre compte utilisateur a été vérifié avec succès, vous pouvez vous connecter!');
  438.                     return $this->redirectToRoute('app_user_login');
  439.                 }
  440.             }
  441.         }
  442.         return $this->render('security/otp_verification.html.twig', [
  443.                 'userId' => $user->getUID(),
  444.                 'formOtp' => $formOtp->createView(),
  445.             ]
  446.         );
  447.     }
  448.     public function resendOtpCodeNew(Request $requestMailerInterface $mailer): Response
  449.     {
  450.         $uID $request->attributes->get('user');
  451.         $user $this->registry->getRepository(Users::class)->findOneBy(['uID' => $uID]);
  452.         if (!$user) {
  453.             throw $this->createNotFoundException(
  454.                 'No user found for id ' $user->getId()
  455.             );
  456.         }
  457.         $otp $this->genOtp();
  458.         $formOtp $this->createForm(OtpChekType::class);
  459.         $formOtp->handleRequest($request);
  460.         $key 'otpData_' $user->getId();
  461.         $otpData $request->getSession()->get($key);
  462.         $user->setOtp($otp);
  463.         $user->setStatus(0);
  464.         $user->setTimeOtp((new \DateTime())->add(new \DateInterval('P3M')));
  465.         $em $this->registry->getManager();
  466.         $em->persist($user);
  467.         $em->flush();
  468.         try {
  469.             if ($otpData === null) {
  470.                 $otpData = [
  471.                     'verificationMode' => "mail",
  472.                     'user' => $user,
  473.                     'attempts' => 1
  474.                 ];
  475.             }
  476.             if ($otpData['attempts'] > 3) {
  477.                 $otpData['attempts'] = 0;
  478.                 $key "otpData_" $user->getId();
  479.                 $request->getSession()->set($key$otpData);
  480.                 $this->addFlash('send_code_error''Vous avez atteint le nombre maximun des tentatives d\'envoi de code otp réssayez plus tard');
  481.             } else {
  482.                 $email = (new Email())
  483.                     ->from($this->getParameter('mailFrom'))
  484.                     ->to($user->getMail())
  485.                     ->subject('Verification Compte Utilisateur')
  486.                     ->text('Vérification de vôtre compte utilisateur')
  487.                     ->html('<p> Cher, ' $user->getMail() . "<br> Nous avons reçu votre demande d'inscription sur la plateforme MOKANDA-RDC www.mokanda-rdc.com , voici votre code de confirmation: " $otp '</p>');
  488.                 $mailer->send($email);
  489.                 $otpData['attempts'] += 1;
  490.                 $key "otpData_" $user->getId();
  491.                 $request->getSession()->set($key$otpData);
  492.                 $this->addFlash('send_code_success''Un nouveau code vous a été renvoyé');
  493.             }
  494.             return $this->redirectToRoute('app_user_otp_check', ['user_id' => $user->getId()]);
  495.         } catch (TransportExceptionInterface $e) {
  496.             $this->logger->info('In Exception transport', [$e->getMessage()]);
  497.             // some error prevented the email sending; display an
  498.             // error message or try to resend the message
  499.             $this->addFlash('user_inscription_fail''Une erreur est survenue lors de l\'inscription, prière contactez le support');
  500.             return $this->redirectToRoute('app_user_inscription');
  501.         }
  502. //        return $this->render(
  503. //            'security/otp_verification.html.twig',
  504. //            [
  505. //                'formOtp' => $formOtp->createView(),
  506. //                'user' => $user
  507. //            ]
  508. //        );
  509.     }
  510.     public function add(Request $requestUserPasswordHasherInterface $passwordHasher): Response
  511.     {
  512.         if ($this->getUser()->getUserType() != && $this->getUser()->getUserType() != 1) {
  513.             $this->addFlash('workspace_alert_warning'"Vous ne pouvez pas accéder à la ressource sollicitée");
  514.             if ($this->getUser()->getUserType() != 4) {
  515.                 return $this->redirectToRoute('app_core_workspace');
  516.             } else {
  517.                 return $this->redirectToRoute('app_core_workspace_surfer');
  518.             }
  519.         }
  520.         $user = new Users();
  521.         $form $this->createForm(SecurityType::class, $user);
  522.         $form->handleRequest($request);
  523.         if ($form->isSubmitted() && $form->isValid()) {
  524.             $user->setPassword(
  525.                 $passwordHasher->hashPassword(
  526.                     $user,
  527.                     '1234'
  528.                 )
  529.             );
  530.             $user->setFirstLogin(true);
  531.             $entityManager $this->registry->getManager();
  532.             $entityManager->persist($user);
  533.             $entityManager->flush();
  534.             $notificationMessage "L'utilisateur " $user->getUsername() . " a été créé et affecté à " $user->getSite()->getLabel() . " par " $this->getUser()->getUserName();
  535.             $this->sendNotificationService->sendMailNotification("Utilisateur Créé"$notificationMessage);
  536.             // do anything else you need here, like send an email
  537.             $this->addFlash('update_user_success''Le compte utilisateur a été créé avec succès !');
  538.             return $this->redirectToRoute('app_user_register');
  539.         }
  540.         return $this->render('security/add.html.twig', [
  541.             'userForm' => $form->createView(),
  542.         ]);
  543.     }
  544.     public function update(Request $request)
  545.     {
  546.         if ($this->getUser()->getUserType() != && $this->getUser()->getUserType() != 1) {
  547.             $this->addFlash('workspace_alert_warning'"Vous ne pouvez pas accéder à la ressource sollicitée");
  548.             return $this->redirectToRoute('app_core_workspace');
  549.         }
  550.         $user $this->registry->getRepository(Users::class)->findOneBy([
  551.             'id' => $request->get('user_id'),
  552.             //'isDeleted' => false,
  553.         ]);
  554.         if ($user === null) {
  555.             $this->addFlash('not_found_user''Le compte utilisateur ' ucfirst($request->get('user_id')) . ' n\'a pas été trouvé');
  556.             return $this->redirectToRoute('app_user_register');
  557.         }
  558.         $username $user->getUsername();
  559.         $login $user->getLogin();
  560.         $userType $this->getUserTypeLabel($user->getUserType());
  561.         $currentSite $user->getSite();
  562.         $mail $user->getMail();
  563.         $telephone $user->getTelephone();
  564.         $userToUpdate $user;
  565.         $notificationMessage "L'utilisateur " $user->getUsername() . " avec l'Id " $user->getId() . " a été modifié par " $this->getUser()->getUserName();
  566.         $form $this->createForm(SecurityType::class, $user);
  567.         $form->handleRequest($request);
  568.         if ($form->isSubmitted() && $form->isValid()) {
  569.             $em $this->registry->getManager();
  570.             $em->persist($user);
  571.             $em->flush();
  572.             //NOTIFICATION MAIL DES MODIFICATIONS
  573.             if ($username !== $user->getUserName()) {
  574.                 $notificationMessage $notificationMessage "<br> Nom de l'utilisateur: " $username "-->" $user->getUserName();
  575.             }
  576.             if ($login !== $user->getLogin()) {
  577.                 $notificationMessage $notificationMessage "<br> Login: " $login "-->" $user->getLogin();
  578.             }
  579.             if ($userType !== $user->getUserType()) {
  580.                 $newProfile $this->getUserTypeLabel($user->getUserType());
  581.                 $notificationMessage $notificationMessage "<br> Profile: " $userType "-->" $newProfile;
  582.             }
  583.             if ($currentSite != null && $user->getSite() != null) {
  584.                 if ($currentSite->getId() !== $user->getSite()->getId()) {
  585.                     $notificationMessage $notificationMessage "<br> Site d'affectation: " $currentSite->getLabel() . "-->" $user->getSite()->getLabel();
  586.                 }
  587.             }
  588.             if ($currentSite == null && $user->getSite() != null) {
  589.                 if ($userToUpdate->getSite()->getId() !== $user->getSite()->getId()) {
  590.                     $notificationMessage $notificationMessage "<br> Site d'affectation: " $user->getSite()->getLabel();
  591.                 }
  592.             }
  593.             if ($mail !== $user->getMail()) {
  594.                 $notificationMessage $notificationMessage "<br> Adresse email: " $mail "-->" $user->getMail();
  595.             }
  596.             if ($telephone !== $user->getTelephone()) {
  597.                 $notificationMessage $notificationMessage "<br> Téléphone: " $telephone "-->" $user->getTelephone();
  598.             }
  599.             $this->logger->info('Contenu du message', [$notificationMessage]);
  600.             $this->sendNotificationService->sendMailNotification("Utilisateur modifié"$notificationMessage);
  601.             $this->addFlash('update_user_success''Le compte utilisateur a été modifié avec succès !');
  602.             return $this->redirectToRoute('app_user_register');
  603.         }
  604.         return $this->render('security/add.html.twig', [
  605.             'userForm' => $form->createView(),
  606.             'user' => $user,
  607.         ]);
  608.     }
  609.     public function removeUser(Request $request)
  610.     {
  611.         $user $this->registry->getRepository(Users::class)->findOneBy([
  612.             'id' => $request->get('user_id'),
  613.             //'isDeleted' => false,
  614.         ]);
  615.         $userDeleted $this->getUser()->getId();
  616.         if ($user === null) {
  617.             $this->addFlash('not_found_user''Le compte utilisateur ' ucfirst($request->get('user_id')) . ' n\'a pas été trouvé');
  618.             return $this->redirectToRoute('app_user_register');
  619.         }
  620.         $em $this->registry->getManager();
  621.         $user->setIsDeleted(true);
  622.         $user->setStatus(false);
  623.         $user->setDeletedDate(new \DateTime());
  624.         $user->setUserDeleted($userDeleted);
  625.         $em->persist($user);
  626.         $em->flush();
  627.         $this->addFlash('su_alert_success'"L'utilisateur " $user->getMail() . " a été desactivé avec succès");
  628.         return $this->redirectToRoute('app_user_register');
  629.     }
  630.     public function activateRoleUser(Request $request)
  631.     {
  632.         $users $this->registry->getRepository(Users::class)->findBy([
  633.             'userType' => $request->get('role_id'),
  634.             'isDeleted' => false,
  635.         ]);
  636.         if ($users === null) {
  637.             $this->addFlash('not_found_user''Aucun compte utilisateur avec le rôle ' ucfirst($request->get('role_id')) . ' n\'a été trouvé');
  638.             return $this->redirectToRoute('app_user_register');
  639.         }
  640.         $em $this->registry->getManager();
  641.         foreach ($users as $u) {
  642.             $u->setStatus(true);
  643.             $em->persist($u);
  644.         }
  645.         $em->flush();
  646.         $this->addFlash('su_alert_success'"Les comptes utilisateurs ont été activés avec succès");
  647.         return $this->redirectToRoute('app_user_register');
  648.     }
  649.     public function disableRoleUser(Request $request)
  650.     {
  651.         $users $this->registry->getRepository(Users::class)->findBy([
  652.             'userType' => $request->get('role_id'),
  653.             'isDeleted' => false,
  654.         ]);
  655.         if ($users === null) {
  656.             $this->addFlash('not_found_user''Aucun compte utilisateur avec le rôle ' ucfirst($request->get('role_id')) . ' n\'a été trouvé');
  657.             return $this->redirectToRoute('app_user_register');
  658.         }
  659.         $em $this->registry->getManager();
  660.         foreach ($users as $u) {
  661.             $u->setStatus(false);
  662.             $em->persist($u);
  663.         }
  664.         $em->flush();
  665.         $this->addFlash('su_alert_success'"Les comptes utilisateurs ont été désactivés avec succès");
  666.         return $this->redirectToRoute('app_user_register');
  667.     }
  668.     public function getUserTypeLabel($type)
  669.     {
  670.         $userTypeLabel "";
  671.         switch ($type) {
  672.             case 1:
  673.                 $userTypeLabel "ADMINISTRATEUR";
  674.                 break;
  675.             case 2:
  676.                 $userTypeLabel "AUTORITE";
  677.                 break;
  678.             case 3:
  679.                 $userTypeLabel "OPS";
  680.                 break;
  681.             case 4:
  682.                 $userTypeLabel "INTERNAUTE";
  683.                 break;
  684.             case 5:
  685.                 $userTypeLabel "VALIDATEUR";
  686.                 break;
  687.             case 6:
  688.                 $userTypeLabel "SUPER-ADMIN";
  689.                 break;
  690.             case 7:
  691.                 $userTypeLabel "UTILISATEUR-RAPPORT";
  692.                 break;
  693.             case 8:
  694.                 $userTypeLabel "SUPERVISEUR";
  695.                 break;
  696.         }
  697.         return $userTypeLabel;
  698.     }
  699.     public function updatePassword(Request $requestUserPasswordHasherInterface $passwordHasherTokenStorageInterface $tokenStorage)
  700.     {
  701.         $user $this->registry->getRepository(Users::class)->findOneBy([
  702.             'id' => $request->get('user_id'),
  703.             'isDeleted' => false,
  704.         ]);
  705.         if ($user === null) {
  706.             $this->addFlash('not_found_user''Le compte utilisateur ' ucfirst($request->get('user_id')) . ' n\'a pas été trouvé');
  707.             return $this->redirectToRoute('app_core_homepage');
  708.         }
  709.         // Redirect to homepage when db user is different to session user
  710.         if ($user != $this->getUser()) {
  711.             return $this->redirectToRoute('app_core_homepage');
  712.         }
  713.         $updatePasswordForm $this->createForm(UpdatePasswordType::class);
  714.         $updatePasswordForm->handleRequest($request);
  715.         if ($updatePasswordForm->isSubmitted() && $updatePasswordForm->isValid()) {
  716.             $data $updatePasswordForm->getData();
  717.             $newPassword $data['password'];
  718.             $oldPassword $data['lastPassword'];
  719.             // Empêchez l'utilisateur d'enregistrer à nouveau l'ancien mot de passe
  720.             if ($oldPassword === $newPassword) {
  721.                 $this->addFlash('update_user_danger''Ce mot de passe a déjà été utilisé, veuillez saisir un nouveau');
  722.                 return $this->redirectToRoute('app_user_update_password', ['user_id' => $user->getId()]);
  723.             }
  724.             $user->setFirstLogin(false);
  725.             $user->setUpdatePasswordDate(new \DateTime());
  726.             $user->setPassword(
  727.                 $passwordHasher->hashPassword(
  728.                     $user,
  729.                     $newPassword
  730.                 )
  731.             );
  732.             $entityManager $this->registry->getManager();
  733.             $entityManager->persist($user);
  734.             $entityManager->flush();
  735.             if ($this->getUser() instanceof UserInterface) {
  736.                 // Déconnectez l'utilisateur en supprimant le token
  737.                 $tokenStorage->setToken(null);
  738.             }
  739.             // do anything else you need here, like send an email
  740.             $this->addFlash('update_user_success''Le compte utilisateur a été créé avec succès !');
  741.             return $this->redirectToRoute('app_user_login');
  742.         }
  743.         return $this->render('security/update_password.html.twig', [
  744.             'updatePasswordForm' => $updatePasswordForm->createView(),
  745.         ]);
  746.     }
  747.     public function forgotPassword(Request $requestMailerInterface $mailer)
  748.     {
  749.         $user = new Users();
  750.         $form $this->createForm(UserIscriptionType::class, $user, ['is_forgot' => true]);
  751.         $form->handleRequest($request);
  752.         $verificationMode null;
  753.         if ($form->isSubmitted() && $form->isValid()) {
  754.             $verificationMode $form->get('verificationMode')->getData();
  755.             $request->getSession()->set('verificationMode'$verificationMode);
  756.             if ($form->isSubmitted() && $form->isValid()) {
  757.                 $otp $this->genOtp();
  758.                 $user $this->em->getRepository(Users::class)->findOneBy(
  759.                     [
  760.                         'mail' => $form->get('plainEmail')->getData()
  761.                     ]
  762.                 );
  763.                 if ($user != null) {
  764.                     $userSendMail $user->getMail();
  765.                     if ($user) {
  766.                         $user->setOtp($otp);
  767.                         $user->setTimeOtp(new \DateTime());
  768.                         $this->em->persist($user);
  769.                         $this->em->flush();
  770.                         // SEND EMAIL
  771.                         try {
  772.                             if ($verificationMode == "sms") {
  773.                                 $response $this->sendSMS($otp$user->getTelephone());
  774.                                 $this->logger->info('REPONSE API SMS', ["----------------------------------------------------------------------------------------------------------------"]);
  775.                                 $this->logger->info('reponse sms', [$response]);
  776.                             } else {
  777.                                 $email = (new Email())
  778.                                     ->from($this->getParameter('mailFrom'))
  779.                                     ->to($user->getMail())
  780.                                     //->to( '[email protected]' )
  781.                                     ->subject('Réinitialisation du mot de passe')
  782.                                     ->text('Réinitialisation effectué avec succès!')
  783.                                     ->html('<p>Cher ' $userSendMail ', nous avons reçu votre demande de réinitialisation de mot de passe sur www.mokanda-rdc.com, voici votre code de confirmation: ' $otp '</p>');
  784.                                 $mailer->send($email);
  785.                                 $this->addFlash('message''le message a été envoyé');
  786.                                 $this->logger->info('After send mail code', []);
  787.                             }
  788.                             $otpData = [
  789.                                 'verificationMode' => $verificationMode,
  790.                                 'user' => $user,
  791.                                 'attempts' => 1
  792.                             ];
  793.                             $key "otpData_" $user->getId();
  794.                             $request->getSession()->set($key$otpData);
  795.                         } catch (\Exception $ex) {
  796.                             /**
  797.                              * TO DO
  798.                              */
  799.                             //$this->addFlash('app_user_forgot_password_mail_failed', "Le mail n'a pas été envoyé. ");
  800.                         }
  801.                     } else {
  802.                         $this->addFlash('user_not_found'"Cet utilisateur n'existe pas dans la base de données");
  803.                         return $this->redirectToRoute('app_user_forgot_password');
  804.                     }
  805.                 } else {
  806.                     $this->addFlash('user_not_found'"Cet utilisateur n'existe pas dans la base de données");
  807.                     return $this->redirectToRoute('app_user_forgot_password');
  808.                 }
  809.             }
  810.             $this->addFlash('app_user_forgot_password_mail_success'"Le mail de réinitialisation a été envoyé avec succès.");
  811.             return $this->redirectToRoute('app_user_otp_check_password_update', ['user_id' => $user->getId()]);
  812.         }
  813.         return $this->render('security/forgot_password.html.twig', [
  814.             'form' => $form->createView(),
  815.         ]);
  816.     }
  817.     public function updatePasswordPublic(Request $requestUserPasswordHasherInterface $passwordHasher)
  818.     {
  819.         $user $this->registry->getRepository(Users::class)->findOneBy([
  820.             'id' => $request->get('user_id'),
  821.             'isDeleted' => false,
  822.         ]);
  823.         if ($user === null) {
  824.             $this->addFlash('not_found_user''Le compte utilisateur ' ucfirst($request->get('user_id')) . ' n\'a pas été trouvé');
  825.             return $this->redirectToRoute('app_core_homepage');
  826.         }
  827.         //if ($this->getUser()->getId() != $user->getId()) {
  828.         //  $this->addFlash('workspace_alert_warning', "Vous ne pouvez pas accéder à la ressource sollicitée");
  829.         //return $this->redirectToRoute('app_core_workspace');
  830.         //}
  831.         $updatePasswordForm $this->createForm(UpdatePasswordType::class);
  832.         $updatePasswordForm->handleRequest($request);
  833.         if ($updatePasswordForm->isSubmitted() && $updatePasswordForm->isValid()) {
  834.             //     $lastPassword = $updatePasswordForm->get('lastPassword')->getData();
  835.             //     $encodedLastPassword = $passwordHasher->hashPassword($user, $lastPassword );
  836.             //     $lastPasswordFromBd = $user->getPassword();
  837.             //     $mach = $passwordHasher->isPasswordValid($this->getUser(), $encodedLastPassword);
  838.             //   if ($mach == false )  {
  839.             //     $this->addFlash('wrongLastPassword', "Votre mot de passe".$encodedLastPassword." est différent de l'ancien, veuillez saisir le mot de passe valide!".$lastPasswordFromBd."");
  840.             //     return $this->redirectToRoute('app_user_update_password', ['user_id' => $this->getUser()->getId()]);
  841.             // }
  842.             $user->setFirstLogin(false);
  843.             $user->setUpdatePasswordDate(new \DateTime());
  844.             $newpassword $updatePasswordForm->getData('password');
  845.             $user->setPassword(
  846.                 $passwordHasher->hashPassword(
  847.                     $user,
  848.                     $newpassword["password"]
  849.                 )
  850.             );
  851.             $entityManager $this->registry->getManager();
  852.             $entityManager->persist($user);
  853.             $entityManager->flush();
  854.             // do anything else you need here, like send an email
  855.             $this->addFlash('update_user_success''Le mot de passe a été mise à jour avec succès !');
  856.             return $this->redirectToRoute('app_user_login');
  857.         }
  858.         return $this->render('security/update_password_forgot.html.twig', [
  859.             'updatePasswordForm' => $updatePasswordForm->createView(),
  860.         ]);
  861.     }
  862.     public function otpchekPasswordUpdate(Request $request)
  863.     {
  864.         $user $this->registry->getRepository(Users::class)->findOneBy([
  865.             'id' => $request->get('user_id'),
  866.             //'isDeleted' => false,
  867.         ]);
  868.         $formOtp2 $this->createForm(OtpChekType::class);
  869.         $formOtp2->handleRequest($request);
  870.         if ($formOtp2->isSubmitted() && $formOtp2->isValid()) {
  871.             $otpParam $formOtp2->get('otp')->getData();
  872.             if ($otpParam != $user->getOtp()) {
  873.                 $this->logger->info('Mauvais OTP', [$otpParam]);
  874.                 $this->addFlash('otp_chek_fail''votre code otp est incorrect ou a expiré!!');
  875.             } else {
  876.                 $user->setStatus(1);
  877.                 $entityManager $this->registry->getManager();
  878.                 $entityManager->persist($user);
  879.                 $entityManager->flush();
  880.                 $this->addFlash('otp_chek_succed''Votre compte utilisateur a été vérifié avec succès, vous pouvez vous connecter!');
  881.                 return $this->redirectToRoute('app_user_update_password_public', ['user_id' => $user->getId()]);
  882.             }
  883.         }
  884.         return $this->render(
  885.             'security/otp_verification_update_pw.html.twig',
  886.             [
  887.                 'formOtp2' => $formOtp2->createView(),
  888.                 'user' => $user
  889.             ]
  890.         );
  891.     }
  892.     public function view(Request $request)
  893.     {
  894.         // Interdire l'accès aux utilisateurs non autorisés
  895.         if ($this->getUser()->getUserType() != 6) {
  896.             $this->addFlash('workspace_alert_warning'"Vous ne pouvez pas accéder à la ressource sollicitée");
  897.             return $this->redirectToRoute('app_core_workspace');
  898.         }
  899.         $user $this->registry->getRepository(Users::class)->findOneBy([
  900.             'id' => $request->get('user_id'),
  901.             //'isDeleted'=> false,
  902.         ]);
  903.         if ($user === null) {
  904.             $this->addFlash('not_found_user''Le compte utilisateur ' ucfirst($request->get('user_id')) . ' n\'a pas été trouvé');
  905.             return $this->redirectToRoute('app_user_register');
  906.         }
  907.         //Récupération des sites de l'utilisateur
  908.         $sus $this->registry->getRepository(SiteUser::class)->findBy([
  909.             'user' => $user->getId(),
  910.             'isDeleted' => false
  911.         ]);
  912.         $em $this->registry->getManager();
  913.         $su = new SiteUser();
  914.         $suForm $this->createForm(SiteUserType::class, $su);
  915.         $suForm->handleRequest($request);
  916.         if ($suForm->isSubmitted() && $suForm->isValid()) {
  917.             $suExist $this->registry->getRepository(SiteUser::class)->findBy([
  918.                 'user' => $user->getId(),
  919.                 'site' => $su->getSite()->getId(),
  920.                 'isDeleted' => false
  921.             ]);
  922.             if (!is_null($suExist) && count($suExist) > 0) {
  923.                 $this->addFlash('su_alert_warning'"Le site " $su->getSite()->getLabel() . " est déjà affecté, impossible de l'affecter une deuxième fois au même utilisateur");
  924.                 return $this->redirectToRoute('app_user_view', [
  925.                     'user_id' => $user->getId(),
  926.                 ]);
  927.             } else {
  928.                 $su->setIsDeleted(false);
  929.                 $su->setUserCreate($this->getUser()->getId() . '');
  930.                 $su->setUser($user);
  931.                 $su->setDateCreate(new \DateTime());
  932.                 $em->persist($su);
  933.                 $em->flush();
  934.                 $this->addFlash('su_alert_success'"Le site " $su->getSite()->getLabel() . " affecté avec succès");
  935.                 return $this->redirectToRoute('app_user_view', [
  936.                     'user_id' => $user->getId(),
  937.                 ]);
  938.             }
  939.         }
  940.         return $this->render('security/view.html.twig', [
  941.             'user' => $user,
  942.             'sus' => $sus,
  943.             'suForm' => $suForm->createView(),
  944.         ]);
  945.     }
  946.     public function suRemove(Request $request)
  947.     {
  948.         $su $this->registry->getRepository(SiteUser::class)->findOneBy([
  949.             'id' => $request->get('su_id'),
  950.             //'isDeleted' => false,
  951.         ]);
  952.         if ($su === null) {
  953.             $this->addFlash('not_found_user''Le compte utilisateur ' ucfirst($request->get('user_id')) . ' n\'a pas été trouvé');
  954.             return $this->redirectToRoute('app_user_register');
  955.         }
  956.         $em $this->registry->getManager();
  957.         $su->setIsDeleted(true);
  958.         $em->persist($su);
  959.         $em->flush();
  960.         $this->addFlash('su_alert_success'"Le site " $su->getSite()->getLabel() . " retiré avec succès");
  961.         return $this->redirectToRoute('app_user_view', [
  962.             'user_id' => $su->getUser()->getId(),
  963.         ]);
  964.     }
  965.     public function profil(Request $requestUserPasswordHasherInterface $passwordHasher)
  966.     {
  967.         $user $this->getUser();
  968.         $form $this->createForm(ProfilFormType::class, $user);
  969.         $form->handleRequest($request);
  970.         if ($form->isSubmitted() && $form->isValid()) {
  971.             $user->setPassword(
  972.                 $passwordHasher->hashPassword(
  973.                     $user,
  974.                     $form->get('password')->getData()
  975.                 )
  976.             );
  977.             $user->setUpdatePasswordDate(new \DateTime());
  978.             $em $this->registry->getManager();
  979.             $em->persist($user);
  980.             $em->flush();
  981.             $this->addFlash('update_profil_success''Votre profil a été modifié avec succès!');
  982.             return $this->redirectToRoute('app_user_profil');
  983.         }
  984.         return $this->render('security/profil.html.twig', [
  985.             'user' => $user,
  986.             'profilForm' => $form->createView(),
  987.         ]);
  988.     }
  989.     public function register(Request $request)
  990.     {
  991.         if ($this->getUser()->getUserType() != 6) {
  992.             $this->addFlash('workspace_alert_warning'"Vous ne pouvez pas accéder à la ressource sollicitée");
  993.             return $this->redirectToRoute('app_core_workspace');
  994.         }
  995.         $users = [];
  996.         $user $this->getUser();
  997.         if ($user->getUserType() == 6) {
  998.             $users $this->registry->getRepository(Users::class)->findAgent();
  999.         } else {
  1000.             $users $this->registry->getRepository(Users::class)->findAgentBySite($user->getSite()->getId());
  1001.         }
  1002.         $roles = [];
  1003.         //$roles[] = ['id' => 6, 'label' => "SUPER ADMINISTRATEUR"];
  1004.         $roles[] = ['id' => 1'label' => "ADMINISTRATEUR"];
  1005.         $roles[] = ['id' => 8'label' => "SUPERVISEUR"];
  1006.         $roles[] = ['id' => 2'label' => "AUTORITE DU SITE"];
  1007.         $roles[] = ['id' => 5'label' => "VALIDATEUR DU SITE"];
  1008.         $roles[] = ['id' => 7'label' => "RAPPORT OPS"];
  1009.         $roles[] = ['id' => 3'label' => "OPERATEUR DE SAISI"];
  1010.         $roles[] = ['id' => 4'label' => "INTERNAUTE"];
  1011.         return $this->render('security/register.html.twig', [
  1012.             'users' => $users,
  1013.             'roles' => $roles,
  1014.         ]);
  1015.     }
  1016.     public function registerSurfer()
  1017.     {
  1018.         if ($this->getUser()->getUserType() != 6) {
  1019.             $this->addFlash('workspace_alert_warning'"Vous ne pouvez pas accéder à la ressource sollicitée");
  1020.             return $this->redirectToRoute('app_core_workspace');
  1021.         }
  1022.         $users = [];
  1023.         $user $this->getUser();
  1024.         if ($user->getUserType() == 6) {
  1025.             $users $this->em->getRepository(Users::class)->findUsersByStatusCustomer();
  1026.         }
  1027.         return $this->render('security/register_surfer.html.twig', [
  1028.             'users' => $users,
  1029.         ]);
  1030.     }
  1031.     public function setStatus(Request $request)
  1032.     {
  1033.         $user $this->registry->getRepository(Users::class)->findOneBy([
  1034.             'id' => $request->get('user_id'),
  1035.             //'isDeleted' => false,
  1036.         ]);
  1037.         if ($user === null) {
  1038.             $this->addFlash('not_found_user''Le compte utilisateur ' ucfirst($request->get('user_id')) . ' n\'a pas été trouvé');
  1039.             return $this->redirectToRoute('app_user_register');
  1040.         }
  1041.         if ($user->getStatus()) {
  1042.             $user->setStatus(false);
  1043.         } else {
  1044.             $user->setStatus(true);
  1045.         }
  1046.         $em $this->registry->getManager();
  1047.         $em->persist($user);
  1048.         $em->flush();
  1049.         if ($user->getStatus()) {
  1050.             $this->addFlash('update_user_success''Compte utilisateur activé avec succès !');
  1051.         } else {
  1052.             $this->addFlash('update_user_success''Compte utilisateur désactivé avec succès !');
  1053.         }
  1054.         return $this->redirectToRoute('app_user_register');
  1055.     }
  1056.     public function goodbye(TokenStorageInterface $tokenStorage): Response
  1057.     {
  1058.         LogManager::save("inconnu""Déconnexion réussie");
  1059.         if ($this->getUser() instanceof UserInterface) {
  1060.             // Déconnectez l'utilisateur en supprimant le token
  1061.             $tokenStorage->setToken(null);
  1062.         }
  1063.         return $this->render('security/logout-goodbye.html.twig');
  1064.     }
  1065.     public function getTokenCsrf(CsrfTokenManagerInterface $csrfTokenManager): JsonResponse
  1066.     {
  1067.         $envCsrfToken $this->getParameter('app_csrf_token');
  1068.         $token $csrfTokenManager->getToken($envCsrfToken);
  1069.         return new JsonResponse(array(
  1070.             "token" => $token->getValue()
  1071.         ));
  1072.     }
  1073. }