src/Controller/HomeController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use App\Entity\AffectationFonctionnalite;
  8. use App\Entity\User;
  9. use App\Repository\AffectationFonctionnaliteRepository;
  10. use App\Repository\LogRepository;
  11. use App\Repository\UserRepository;
  12. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use App\Fonctions\Fonctions;
  15. use Symfony\Component\Mailer\MailerInterface;
  16. use Symfony\Component\Mime\Email;
  17. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  18. use Symfony\Component\Mime\Address;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class HomeController extends AbstractController
  21. {
  22.     public function __construct(AffectationFonctionnaliteRepository $AffectationFonctionnaliteRepository,?UserInterface $user,SessionInterface $session,Fonctions $fonct,EntityManagerInterface $em)
  23.     {
  24.        
  25.         $this->getUser $user;
  26.         $this->em $em;
  27.         $this->fonct $fonct;
  28.         $this->session $session;
  29.         $this->AffectationFonctionnaliteRepository $AffectationFonctionnaliteRepository;
  30.     }
  31.     #[Route('/app_code_security'name'app_code_security')]
  32.     public function app_code_security(Request $request,UserPasswordHasherInterface $passwordHasher,MailerInterface $mailer): Response
  33.     {
  34.        // dd(1);
  35.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  36.         if ($this->getUser()->getStatut()!=1) {
  37.             $user=$this->getUser();
  38.             $action="Authentification";
  39.             $statut="Echouée";
  40.             $msg="Votre compte a été verrouiller, veuillez contacter votre superviseur";
  41.             $entity="User";
  42.             $identity="";
  43.             $old_v="";
  44.             $new_v="";
  45.             $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  46.             $this->em->persist($log);
  47.             $this->em->flush();
  48.             $this->addFlash('logout','Votre compte a été verrouiller, veuillez contacter votre superviseur');
  49.             return $this->redirectToRoute('first_logout');
  50.         }
  51.         if ($this->getUser()->isFirstConnexion()==1) {
  52.         $code_verfier=$this->generercodeInit();
  53.         $hashedPassword $passwordHasher->hashPassword(
  54.             $this->getUser(),
  55.             $code_verfier
  56.             );
  57.         $date = new \DateTime('now');
  58.          $this->session->set('code_verif'$hashedPassword);
  59.          $this->session->set('date'$date);
  60.           $otp=$this->session->get('OTP');
  61.          //dd()
  62.          if ($otp==" ") {
  63.              // code...
  64.              return $this->redirectToRoute('app_logout');
  65.               
  66.          }else{
  67.             if ($otp=="1") {
  68.                 // code...
  69.                  $contenu="Votre code de verification: ".$code_verfier;
  70.                  $nbrecaractere=strlen($contenu);
  71.                  $sms$this->fonct->envoi_sms($this->getUser()->getTelephone(),$contenu);
  72.                  $this->session->set('OTP'," ");
  73.             }else{
  74.                  $email = (new TemplatedEmail())
  75.                     ->from(new Address('crm-garbal@noreply.airtel.africa','CRM GARBAL'))
  76.                     ->to(new Address($this->getUser()->getEmail()))
  77.                     ->subject('Code de verification pour acceder a votre espace Client!')
  78.                     ->htmlTemplate('security/text.html.twig')
  79.                     ->context([
  80.                         'username' => $this->getUser(),
  81.                         'code' => $code_verfier,
  82.                     ]);
  83.                  $mailer->send($email);
  84.                  $this->session->set('OTP'," ");
  85.             }
  86.          }
  87.          // $contenu="Votre code de verification: ".$code_verfier;
  88.          // $nbrecaractere=strlen($contenu);
  89.           
  90.                 // dd($nbrecaractere, $contenu);
  91.          //$sms= $this->fonct->envoi_sms(91056163,$contenu);
  92.         $user=$this->getUser();
  93.         $action="Authentification";
  94.         $statut="Success";
  95.         $msg="Email envoyé: recuperation de OTP";
  96.         $entity="User";
  97.         $identity="";
  98.         $old_v="";
  99.         $new_v="";
  100.         $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  101.         $this->em->persist($log);
  102.         $this->em->flush();
  103.         return $this->redirectToRoute('verification_compte');
  104.       }else{
  105.         $user=$this->getUser();
  106.         $action="Authentification";
  107.         $statut="Success";
  108.         $msg="Premiere connexion";
  109.         $entity="User";
  110.         $identity="";
  111.         $old_v="";
  112.         $new_v="";
  113.         $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  114.         $this->em->persist($log);
  115.         $this->em->flush();
  116.          return $this->render('security/first_connexion.html.twig', [
  117.         'controller_name' => 'HomeController',
  118.         'error' => '',
  119.         ]);
  120.         
  121.       }
  122.     }
  123.     #[Route('/home'name'app_home')]
  124.     public function index(Request $request,AffectationFonctionnaliteRepository $AffectationFonctionnaliteRepository): Response
  125.     {
  126.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  127.         //a enlever
  128.          $this->session->set('active_fonction',1);
  129.         if ($this->getUser()->isFirstConnexion()==1) {
  130.             // code...
  131.         if (in_array('ROLE_ADMINISTRATEUR'$this->getUser()->getRoles())==true || in_array('ROLE_COLLECTEUR'$this->getUser()->getRoles())==true) {
  132.             if (in_array('ROLE_ADMINISTRATEUR'$this->getUser()->getRoles())==true) {
  133.                  $this->session->set('select'1);
  134.                  $this->session->set('Sousselect'1);
  135.                 // code...
  136.             }else{
  137.                  $this->session->set('Sousselect'1);
  138.                  $this->session->set('select'22);
  139.             }
  140.             // dd('1');
  141.             return $this->render('home/index.html.twig', [
  142.             'controller_name' => 'HomeController',
  143.         ]);
  144.             // code...
  145.         }elseif (in_array('ROLE_TELECONSEILLER'$this->getUser()->getRoles())==true) {
  146.                 $this->session->set('select'7);
  147.             return $this->redirectToRoute('app_dashboard');
  148.         //      return $this->render('home/index.html.twig', [
  149.         //     'controller_name' => 'HomeController',
  150.         // ]);
  151.             // code...
  152.          }elseif (in_array('ROLE_SUPERVISEUR'$this->getUser()->getRoles())==true) {
  153.                 $this->session->set('select'34);
  154.             return $this->redirectToRoute('app_dashboard_superviseur');
  155.         //      return $this->render('home/index.html.twig', [
  156.         //     'controller_name' => 'HomeController',
  157.         // ]);
  158.             // code...
  159.          }elseif (in_array('ROLE_SNV'$this->getUser()->getRoles())==true) {
  160.                              $this->session->set('select'17);
  161.            return $this->redirectToRoute('app_rapport_historique_appel');
  162.         //      return $this->render('home/index.html.twig', [
  163.         //     'controller_name' => 'HomeController',
  164.         // ]);
  165.             // code...
  166.         }elseif (in_array('ROLE_PARTENAIRE_MARKETPLACE'$this->getUser()->getRoles())==true) {
  167.             $this->session->set('select'29);
  168.             $this->session->set('Sousselect'57);
  169.             // dd($this->getUser()->getRoles());
  170.          return $this->render('plaintes/home.html.twig', [
  171.                 'controller_name' => 'HomeController',
  172.             ]);
  173.      
  174.         }else{
  175.             
  176.             
  177.              return $this->render('home/index.html.twig', [
  178.             'controller_name' => 'HomeController',
  179.         ]);
  180.         }
  181.         }else{
  182.              return $this->render('security/first_connexion.html.twig', [
  183.             'controller_name' => 'HomeController',
  184.             'error' => '',
  185.         ]);
  186.             
  187.         }
  188.     }
  189.       #[Route('/update_password/profil'name'update_password_profil')]
  190.     public function update_password_profil(Request $request,UserPasswordHasherInterface $passwordHasher,EntityManagerInterface $manger): Response
  191.     {
  192.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  193.         if ($request->request->count()>0){
  194.             $password=$request->request->get('password');
  195.             $confirm_password=$request->request->get('confirm_password');
  196.             $ancien_password=$request->request->get('ancien_password');
  197.             $user=$this->getUser();
  198.             $pattern "/([a-z])/i";
  199.             $pattern1 "/([0-9])/";
  200.             $pattern2 "/[@\.\-\+\_\*\#\&]/";
  201.             //dd(preg_match($pattern, $password),preg_match($pattern1, $password),preg_match($pattern2, $password),$password); 
  202.             if( password_verify($ancien_password$user->getPassword())) {
  203.             if (preg_match($pattern$password)==&& preg_match($pattern1$password) && preg_match($pattern2$password)) {
  204.                 if ($password==$confirm_password) {
  205.                     // hash the password (based on the security.yaml config for the $user class)
  206.                     $hashedPassword $passwordHasher->hashPassword(
  207.                         $user,
  208.                         $password
  209.                     );
  210.                     $user->setPassword($hashedPassword);
  211.                     $user->setFirstConnexion(1);
  212.                     $manger->persist($user);
  213.                     $manger->flush();
  214.                     $user=$this->getUser();
  215.                     $action="Changement mot de passe profil";
  216.                     $statut="Success";
  217.                     $msg="Votre mot de passe a été changer avec succés";
  218.                     $entity="User";
  219.                     $identity="";
  220.                     $old_v="";
  221.                     $new_v="";
  222.                     $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  223.                     $this->em->persist($log);
  224.                     $this->em->flush();
  225.                     return $this->redirectToRoute('app_home');
  226.                     // code...
  227.                 }else{
  228.                     $user=$this->getUser();
  229.                     $action="Changement mot de passe profil";
  230.                     $statut="Echouée";
  231.                     $msg="Les deux mots de passe ne sont pas identiques";
  232.                     $entity="User";
  233.                     $identity="";
  234.                     $old_v="";
  235.                     $new_v="";
  236.                     $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  237.                     $this->em->persist($log);
  238.                     $this->em->flush();
  239.                     return $this->render('security/update_password.html.twig', [
  240.                     'controller_name' => 'AccueilController',
  241.                     'error' => 'Les deux mots de passe ne sont pas identiques',
  242.                     ]);
  243.                 }
  244.                 // code...
  245.             }else{
  246.                 $user=$this->getUser();
  247.                 $action="Changement mot de passe profil";
  248.                 $statut="Echouée";
  249.                 $msg="le mot de passe doit contenir au moins 6 characteres dont au moins une lettre, un chiffre et un symbole (&#@.-+_*)";
  250.                 $entity="User";
  251.                 $identity="";
  252.                 $old_v="";
  253.                 $new_v="";
  254.                 $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  255.                 $this->em->persist($log);
  256.                 $this->em->flush();
  257.                  return $this->render('security/update_password.html.twig', [
  258.                     'controller_name' => 'AccueilController',
  259.                     'error' => 'le mot de passe doit contenir au moins 6 characteres dont au moins une lettre, un chiffre et un symbole (&#@.-+_*) ',
  260.                     ]);
  261.             }
  262.             }else{
  263.                 $user=$this->getUser();
  264.                 $action="Changement mot de passe profil";
  265.                 $statut="Echouée";
  266.                 $msg="Votre ancien mot de passe est incorrect";
  267.                 $entity="User";
  268.                 $identity="";
  269.                 $old_v="";
  270.                 $new_v="";
  271.                 $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  272.                 $this->em->persist($log);
  273.                 $this->em->flush();
  274.                  return $this->render('security/update_password.html.twig', [
  275.                     'controller_name' => 'AccueilController',
  276.                     'error' => 'Votre ancien mot de passe est incorrect',
  277.                     ]);
  278.             }
  279.             
  280.             // code...
  281.         }
  282.         
  283.         
  284.         return $this->render('security/update_password.html.twig', [
  285.             'controller_name' => 'AccueilController',
  286.             'error' => "",
  287.         ]);
  288.     }
  289.     #[Route('/update_password'name'update_password')]
  290.     public function update_password(Request $request,UserPasswordHasherInterface $passwordHasher,EntityManagerInterface $manger): Response
  291.     {
  292.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  293.         if ($request->request->count()>0){
  294.             $password=$request->request->get('password');
  295.             $confirm_password=$request->request->get('confirm_password');
  296.             $user=$this->getUser();
  297.             $pattern "/([a-z])/i";
  298.             $pattern1 "/([0-9])/";
  299.             $pattern2 "/[@\.\-\+\_\*\#\&]/";
  300.             //dd(preg_match($pattern, $password),preg_match($pattern1, $password),preg_match($pattern2, $password),$password); 
  301.             if (preg_match($pattern$password)==&& preg_match($pattern1$password) && preg_match($pattern2$password)) {
  302.                 if ($password==$confirm_password) {
  303.                     // hash the password (based on the security.yaml config for the $user class)
  304.                     $hashedPassword $passwordHasher->hashPassword(
  305.                         $user,
  306.                         $password
  307.                     );
  308.                     $user->setPassword($hashedPassword);
  309.                     $user->setFirstConnexion(1);
  310.                     $manger->persist($user);
  311.                     $manger->flush();
  312.                     $user=$this->getUser();
  313.                     $action="Changement mot de passe";
  314.                     $statut="Success";
  315.                     $msg="Votre mot de passe a été changer avec succés";
  316.                     $entity="User";
  317.                     $identity="";
  318.                     $old_v="";
  319.                     $new_v="";
  320.                     $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  321.                     $this->em->persist($log);
  322.                     $this->em->flush();
  323.                     return $this->redirectToRoute('app_logout');
  324.                     // code...
  325.                 }else{
  326.                     $user=$this->getUser();
  327.                     $action="Changement mot de passe";
  328.                     $statut="Echouée";
  329.                     $msg="Les deux mots de passe ne sont pas identiques";
  330.                     $entity="User";
  331.                     $identity="";
  332.                     $old_v="";
  333.                     $new_v="";
  334.                     $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  335.                     $this->em->persist($log);
  336.                     $this->em->flush();
  337.                     return $this->render('security/first_connexion.html.twig', [
  338.                     'controller_name' => 'AccueilController',
  339.                     'error' => 'Les deux mots de passe ne sont pas identiques',
  340.                     ]);
  341.                 }
  342.                 // code...
  343.             }else{
  344.                 $user=$this->getUser();
  345.                 $action="Changement mot de passe";
  346.                 $statut="Echouée";
  347.                 $msg="le mot de passe doit contenir au moins 6 characteres dont au moins une lettre, un chiffre et un symbole (&#@.-+_*)";
  348.                 $entity="User";
  349.                 $identity="";
  350.                 $old_v="";
  351.                 $new_v="";
  352.                 $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  353.                 $this->em->persist($log);
  354.                 $this->em->flush();
  355.                  return $this->render('security/first_connexion.html.twig', [
  356.                     'controller_name' => 'AccueilController',
  357.                     'error' => 'le mot de passe doit contenir au moins 6 characteres dont au moins une lettre, un chiffre et un symbole (&#@.-+_*) ',
  358.                     ]);
  359.             }
  360.             
  361.             // code...
  362.         }
  363.         
  364.         
  365.         return $this->render('security/verification_compte.html.twig', [
  366.             'controller_name' => 'AccueilController',
  367.             'error' => "",
  368.         ]);
  369.     }
  370.  #[Route('/MonProfil/{id}'name'app_user_monprofil'methods: ['GET','POST'])]
  371.     public function show(EntityManagerInterface $em,Request $request,User $user,AffectationFonctionnaliteRepository $AffectationFonctionnaliteRepository,UserRepository $userRepository,LogRepository $LogRepository): Response
  372.     {
  373.        // dd(1);
  374.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  375.       
  376.         $affectationFonctionProfil=$AffectationFonctionnaliteRepository->findBy(['id_user'=>$user->getId(),'statut'=>[0,1],'id_sous_fonctionnalite'=>null]);
  377.         $log=$LogRepository->findBy(['id_user'=>$user->getId()],['id'=>'DESC'],25);
  378.         $sousFonction=array();
  379.         foreach ($affectationFonctionProfil as $key) {
  380.              if ($key->getIdFonctionnalite()->getIdFonctionnalite()->getLien()=="#") {
  381.                  $sousFonction[$key->getIdFonctionnalite()->getId()]=$AffectationFonctionnaliteRepository->listeSous($user->getId(),$key->getIdFonctionnalite());
  382.                  // code...
  383.              }
  384.             
  385.             // code...
  386.         }
  387.         
  388.         return $this->render('admin/user/profil.html.twig', [
  389.             'user' => $user,
  390.             'log' => $log,
  391.             'menu' => $affectationFonctionProfil,
  392.             'sousmenu' => $sousFonction,
  393.         ]);
  394.     }
  395.     public function MenuSection()
  396.       {  
  397.         $nenu=array();
  398.         $menu['onglet']=$this->AffectationFonctionnaliteRepository->findListeOngletBy($this->getUser()->getId());
  399.         foreach ($menu['onglet'] as $key) {
  400.             $menu['menu'][$key->getId()]=$this->AffectationFonctionnaliteRepository->findBy(['id_user'=>$this->getUser()->getId(),'statut'=>1,'id_onglet'=>$key->getId()]);
  401.             foreach ($menu['menu'][$key->getId()] as $value) {
  402.                 if ($value->getIdFonctionnalite()->getIdFonctionnalite()->getLien()=="#") {
  403.                     $menu['sousmenu'][$value->getIdFonctionnalite()->getId()]=$this->AffectationFonctionnaliteRepository->listeSousMenu($this->getUser()->getId(),$value->getIdFonctionnalite()->getId());
  404.                     // code...
  405.                 }
  406.                 // code...
  407.             }
  408.            
  409.             // code...
  410.         }
  411.         return $menu;
  412.       }
  413.     public function generercodeInit()
  414.       {
  415.           $haz=array(1,
  416.             rand(2,3),
  417.             rand(4,5),
  418.             rand(6,7),
  419.             rand(8,9),0);
  420.             shuffle($haz);
  421.             $co="";
  422.             $i=0;
  423.             while($i<6){
  424.             $co.= $haz[$i];
  425.             if(!in_array($co,$haz)){
  426.             }else{}
  427.             $i++;
  428.             }
  429.            return $co;
  430.           
  431.       }  
  432.     
  433. }