src/Controller/HomeController.php line 28

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.         }elseif (in_array('ROLE_COLLECTEUR_ABC'$this->getUser()->getRoles())==true) {
  175.             $this->session->set('select'33);
  176.             $this->session->set('Sousselect'96);
  177.             // dd($this->getUser()->getRoles());
  178.          return $this->render('abc/home.html.twig', [
  179.                 'controller_name' => 'HomeController',
  180.             ]);
  181.      
  182.         }else{
  183.             
  184.             
  185.              return $this->render('home/index.html.twig', [
  186.             'controller_name' => 'HomeController',
  187.         ]);
  188.         }
  189.         }else{
  190.              return $this->render('security/first_connexion.html.twig', [
  191.             'controller_name' => 'HomeController',
  192.             'error' => '',
  193.         ]);
  194.             
  195.         }
  196.     }
  197.       #[Route('/update_password/profil'name'update_password_profil')]
  198.     public function update_password_profil(Request $request,UserPasswordHasherInterface $passwordHasher,EntityManagerInterface $manger): Response
  199.     {
  200.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  201.         if ($request->request->count()>0){
  202.             $password=$request->request->get('password');
  203.             $confirm_password=$request->request->get('confirm_password');
  204.             $ancien_password=$request->request->get('ancien_password');
  205.             $user=$this->getUser();
  206.             $pattern "/([a-z])/i";
  207.             $pattern1 "/([0-9])/";
  208.             $pattern2 "/[@\.\-\+\_\*\#\&]/";
  209.             //dd(preg_match($pattern, $password),preg_match($pattern1, $password),preg_match($pattern2, $password),$password); 
  210.             if( password_verify($ancien_password$user->getPassword())) {
  211.             if (preg_match($pattern$password)==&& preg_match($pattern1$password) && preg_match($pattern2$password)) {
  212.                 if ($password==$confirm_password) {
  213.                     // hash the password (based on the security.yaml config for the $user class)
  214.                     $hashedPassword $passwordHasher->hashPassword(
  215.                         $user,
  216.                         $password
  217.                     );
  218.                     $user->setPassword($hashedPassword);
  219.                     $user->setFirstConnexion(1);
  220.                     $manger->persist($user);
  221.                     $manger->flush();
  222.                     $user=$this->getUser();
  223.                     $action="Changement mot de passe profil";
  224.                     $statut="Success";
  225.                     $msg="Votre mot de passe a été changer avec succés";
  226.                     $entity="User";
  227.                     $identity="";
  228.                     $old_v="";
  229.                     $new_v="";
  230.                     $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  231.                     $this->em->persist($log);
  232.                     $this->em->flush();
  233.                     return $this->redirectToRoute('app_home');
  234.                     // code...
  235.                 }else{
  236.                     $user=$this->getUser();
  237.                     $action="Changement mot de passe profil";
  238.                     $statut="Echouée";
  239.                     $msg="Les deux mots de passe ne sont pas identiques";
  240.                     $entity="User";
  241.                     $identity="";
  242.                     $old_v="";
  243.                     $new_v="";
  244.                     $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  245.                     $this->em->persist($log);
  246.                     $this->em->flush();
  247.                     return $this->render('security/update_password.html.twig', [
  248.                     'controller_name' => 'AccueilController',
  249.                     'error' => 'Les deux mots de passe ne sont pas identiques',
  250.                     ]);
  251.                 }
  252.                 // code...
  253.             }else{
  254.                 $user=$this->getUser();
  255.                 $action="Changement mot de passe profil";
  256.                 $statut="Echouée";
  257.                 $msg="le mot de passe doit contenir au moins 6 characteres dont au moins une lettre, un chiffre et un symbole (&#@.-+_*)";
  258.                 $entity="User";
  259.                 $identity="";
  260.                 $old_v="";
  261.                 $new_v="";
  262.                 $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  263.                 $this->em->persist($log);
  264.                 $this->em->flush();
  265.                  return $this->render('security/update_password.html.twig', [
  266.                     'controller_name' => 'AccueilController',
  267.                     'error' => 'le mot de passe doit contenir au moins 6 characteres dont au moins une lettre, un chiffre et un symbole (&#@.-+_*) ',
  268.                     ]);
  269.             }
  270.             }else{
  271.                 $user=$this->getUser();
  272.                 $action="Changement mot de passe profil";
  273.                 $statut="Echouée";
  274.                 $msg="Votre ancien mot de passe est incorrect";
  275.                 $entity="User";
  276.                 $identity="";
  277.                 $old_v="";
  278.                 $new_v="";
  279.                 $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  280.                 $this->em->persist($log);
  281.                 $this->em->flush();
  282.                  return $this->render('security/update_password.html.twig', [
  283.                     'controller_name' => 'AccueilController',
  284.                     'error' => 'Votre ancien mot de passe est incorrect',
  285.                     ]);
  286.             }
  287.             
  288.             // code...
  289.         }
  290.         
  291.         
  292.         return $this->render('security/update_password.html.twig', [
  293.             'controller_name' => 'AccueilController',
  294.             'error' => "",
  295.         ]);
  296.     }
  297.     #[Route('/update_password'name'update_password')]
  298.     public function update_password(Request $request,UserPasswordHasherInterface $passwordHasher,EntityManagerInterface $manger): Response
  299.     {
  300.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  301.         if ($request->request->count()>0){
  302.             $password=$request->request->get('password');
  303.             $confirm_password=$request->request->get('confirm_password');
  304.             $user=$this->getUser();
  305.             $pattern "/([a-z])/i";
  306.             $pattern1 "/([0-9])/";
  307.             $pattern2 "/[@\.\-\+\_\*\#\&]/";
  308.             //dd(preg_match($pattern, $password),preg_match($pattern1, $password),preg_match($pattern2, $password),$password); 
  309.             if (preg_match($pattern$password)==&& preg_match($pattern1$password) && preg_match($pattern2$password)) {
  310.                 if ($password==$confirm_password) {
  311.                     // hash the password (based on the security.yaml config for the $user class)
  312.                     $hashedPassword $passwordHasher->hashPassword(
  313.                         $user,
  314.                         $password
  315.                     );
  316.                     $user->setPassword($hashedPassword);
  317.                     $user->setFirstConnexion(1);
  318.                     $manger->persist($user);
  319.                     $manger->flush();
  320.                     $user=$this->getUser();
  321.                     $action="Changement mot de passe";
  322.                     $statut="Success";
  323.                     $msg="Votre mot de passe a été changer avec succés";
  324.                     $entity="User";
  325.                     $identity="";
  326.                     $old_v="";
  327.                     $new_v="";
  328.                     $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  329.                     $this->em->persist($log);
  330.                     $this->em->flush();
  331.                     return $this->redirectToRoute('app_logout');
  332.                     // code...
  333.                 }else{
  334.                     $user=$this->getUser();
  335.                     $action="Changement mot de passe";
  336.                     $statut="Echouée";
  337.                     $msg="Les deux mots de passe ne sont pas identiques";
  338.                     $entity="User";
  339.                     $identity="";
  340.                     $old_v="";
  341.                     $new_v="";
  342.                     $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  343.                     $this->em->persist($log);
  344.                     $this->em->flush();
  345.                     return $this->render('security/first_connexion.html.twig', [
  346.                     'controller_name' => 'AccueilController',
  347.                     'error' => 'Les deux mots de passe ne sont pas identiques',
  348.                     ]);
  349.                 }
  350.                 // code...
  351.             }else{
  352.                 $user=$this->getUser();
  353.                 $action="Changement mot de passe";
  354.                 $statut="Echouée";
  355.                 $msg="le mot de passe doit contenir au moins 6 characteres dont au moins une lettre, un chiffre et un symbole (&#@.-+_*)";
  356.                 $entity="User";
  357.                 $identity="";
  358.                 $old_v="";
  359.                 $new_v="";
  360.                 $log=$this->fonct->log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v);
  361.                 $this->em->persist($log);
  362.                 $this->em->flush();
  363.                  return $this->render('security/first_connexion.html.twig', [
  364.                     'controller_name' => 'AccueilController',
  365.                     'error' => 'le mot de passe doit contenir au moins 6 characteres dont au moins une lettre, un chiffre et un symbole (&#@.-+_*) ',
  366.                     ]);
  367.             }
  368.             
  369.             // code...
  370.         }
  371.         
  372.         
  373.         return $this->render('security/verification_compte.html.twig', [
  374.             'controller_name' => 'AccueilController',
  375.             'error' => "",
  376.         ]);
  377.     }
  378.  #[Route('/MonProfil/{id}'name'app_user_monprofil'methods: ['GET','POST'])]
  379.     public function show(EntityManagerInterface $em,Request $request,User $user,AffectationFonctionnaliteRepository $AffectationFonctionnaliteRepository,UserRepository $userRepository,LogRepository $LogRepository): Response
  380.     {
  381.        // dd(1);
  382.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  383.       
  384.         $affectationFonctionProfil=$AffectationFonctionnaliteRepository->findBy(['id_user'=>$user->getId(),'statut'=>[0,1],'id_sous_fonctionnalite'=>null]);
  385.         $log=$LogRepository->findBy(['id_user'=>$user->getId()],['id'=>'DESC'],25);
  386.         $sousFonction=array();
  387.         foreach ($affectationFonctionProfil as $key) {
  388.              if ($key->getIdFonctionnalite()->getIdFonctionnalite()->getLien()=="#") {
  389.                  $sousFonction[$key->getIdFonctionnalite()->getId()]=$AffectationFonctionnaliteRepository->listeSous($user->getId(),$key->getIdFonctionnalite());
  390.                  // code...
  391.              }
  392.             
  393.             // code...
  394.         }
  395.         
  396.         return $this->render('admin/user/profil.html.twig', [
  397.             'user' => $user,
  398.             'log' => $log,
  399.             'menu' => $affectationFonctionProfil,
  400.             'sousmenu' => $sousFonction,
  401.         ]);
  402.     }
  403.     public function MenuSection()
  404.       {  
  405.         $nenu=array();
  406.         $menu['onglet']=$this->AffectationFonctionnaliteRepository->findListeOngletBy($this->getUser()->getId());
  407.         foreach ($menu['onglet'] as $key) {
  408.             $menu['menu'][$key->getId()]=$this->AffectationFonctionnaliteRepository->findBy(['id_user'=>$this->getUser()->getId(),'statut'=>1,'id_onglet'=>$key->getId()]);
  409.             foreach ($menu['menu'][$key->getId()] as $value) {
  410.                 if ($value->getIdFonctionnalite()->getIdFonctionnalite()->getLien()=="#") {
  411.                     $menu['sousmenu'][$value->getIdFonctionnalite()->getId()]=$this->AffectationFonctionnaliteRepository->listeSousMenu($this->getUser()->getId(),$value->getIdFonctionnalite()->getId());
  412.                     // code...
  413.                 }
  414.                 // code...
  415.             }
  416.            
  417.             // code...
  418.         }
  419.         return $menu;
  420.       }
  421.     public function generercodeInit()
  422.       {
  423.           $haz=array(1,
  424.             rand(2,3),
  425.             rand(4,5),
  426.             rand(6,7),
  427.             rand(8,9),0);
  428.             shuffle($haz);
  429.             $co="";
  430.             $i=0;
  431.             while($i<6){
  432.             $co.= $haz[$i];
  433.             if(!in_array($co,$haz)){
  434.             }else{}
  435.             $i++;
  436.             }
  437.            return $co;
  438.           
  439.       }  
  440.     
  441. }