src/Controller/Users/User/SecurityController.php line 113

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Users\User;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  7. use App\Security\TokenAuthenticator;
  8. use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
  9. use App\Entity\Users\User\User;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use App\Entity\Users\User\Slideaccueil;
  12. use App\Service\Servicetext\GeneralServicetext;
  13. use App\Entity\Users\Adminuser\Parametre;
  14. use App\Entity\Projet\Partenaire\Partenaire;
  15. use App\Entity\Produit\Service\Testimonial;
  16. use App\Entity\Produit\Service\Team;
  17. use App\Entity\Produit\Service\Faq;
  18. use App\Entity\Produit\Service\Article;
  19. use App\Entity\Projet\Portfolio\Intervention;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use App\Entity\Produit\Produit\Produit;
  22. use App\Entity\Produit\Service\Service;
  23. class SecurityController extends AbstractController
  24. {
  25.     private $params;
  26.     private $authenticator;
  27.     private $guardHandler;
  28.     private $_entityManager;
  29.     public function __construct(ParameterBagInterface $paramsTokenAuthenticator $authenticatorGuardAuthenticatorHandler $guardHandlerEntityManagerInterface $entityManager)
  30.     {
  31.         $this->params $params;
  32.         $this->authenticator $authenticator;
  33.         $this->guardHandler $guardHandler;
  34.         $this->_entityManager $entityManager;
  35.     }
  36.     public function accueilsite(GeneralServicetext $service)
  37.     {
  38.         /*$var = '["val une", "val 2"]';
  39.         $var = json_decode($var, TRUE);
  40.         print_r($var);
  41.         exit;*/
  42.         $liste_slide $this->_entityManager->getRepository(Slideaccueil::class)
  43.                                             ->findAll();
  44.         $slide $service->selectEntity($liste_slide);
  45.         $aboutParam $this->_entityManager->getRepository(Parametre::class)
  46.                                            ->findOneBy(array('typeParam'=>'aboutWithArticle'), array('rang'=>'asc'), 1);
  47.         if($aboutParam != null)
  48.         {
  49.             $aboutParam->setEm($this->_entityManager);
  50.         }
  51.         $liste_partenaire $this->_entityManager->getRepository(Partenaire::class)
  52.                                             ->findAll();
  53.         $aboutService $this->_entityManager->getRepository(Parametre::class)
  54.                                              ->findOneBy(array('typeParam'=>'detailservice'), array('rang'=>'asc'), 1);
  55.         $aboutTestimonial $this->_entityManager->getRepository(Parametre::class)
  56.                                                  ->findOneBy(array('typeParam'=>'detailtestimonial'), array('rang'=>'asc'), 1);
  57.         $liste_testimonial $this->_entityManager->getRepository(Testimonial::class)
  58.                                                  ->myfindAll();
  59.         $aboutCalltoaction $this->_entityManager->getRepository(Parametre::class)
  60.                                                   ->findOneBy(array('typeParam'=>'calltoaction'), array('rang'=>'asc'), 1);
  61.         $aboutDetailteam $this->_entityManager->getRepository(Parametre::class)
  62.                                                 ->findOneBy(array('typeParam'=>'detailteam'), array('rang'=>'asc'), 1);
  63.         $liste_team $this->_entityManager->getRepository(Team::class)
  64.                                            ->myfindAll();
  65.         $aboutPricing $this->_entityManager->getRepository(Parametre::class)
  66.                                               ->findOneBy(array('typeParam'=>'detailpricing'), array('rang'=>'asc'), 1);
  67.         $aboutFaq $this->_entityManager->getRepository(Parametre::class)
  68.                                         ->findOneBy(array('typeParam'=>'detailfaq'), array('rang'=>'asc'), 1);
  69.         $aboutBlog $this->_entityManager->getRepository(Parametre::class)
  70.                                         ->findOneBy(array('typeParam'=>'detailblog'), array('rang'=>'asc'), 1);
  71.         $liste_faq $this->_entityManager->getRepository(Faq::class)
  72.                                            ->myfindAll();
  73.         $liste_blog $this->_entityManager->getRepository(Article::class)
  74.                                            ->myfindAll(1,6);
  75.         $aboutIntervention $this->_entityManager->getRepository(Parametre::class)
  76.                                            ->findOneBy(array('typeParam'=>'detailintervention'), array('rang'=>'asc'), 1);
  77.         $liste_intervention $this->_entityManager->getRepository(Intervention::class)
  78.                                            ->findTopProjet();
  79.         foreach($liste_intervention as $intervention)
  80.         {
  81.             $intervention->setEm($this->_entityManager);
  82.         }
  83.         $liste_produit $this->_entityManager->getRepository(Produit::class)
  84.                               ->myFindBy();
  85.         foreach($liste_produit as $produitCurrent)
  86.         {
  87.             $produitCurrent->setEm($this->_entityManager);
  88.         }
  89.         
  90.         $repository $this->_entityManager->getRepository(Service::class);
  91.         $liste_service $repository->findServiceTypePagine("service"120);
  92.         $liste_service $service->selectEntities($liste_service6);
  93.         $repository $this->_entityManager->getRepository(Service::class);
  94.         $liste_departement $repository->findServiceTypePagine("departement"120);
  95.         $liste_departement $service->selectEntities($liste_departement6);
  96.         return $this->render($service->getThemeDirectory().'/Users/User/Security/accueilsite.html.twig',
  97.         array('slide'=>$slide'aboutParam'=>$aboutParam'liste_partenaire'=>$liste_partenaire'aboutService'=>$aboutService,
  98.         'aboutTestimonial'=>$aboutTestimonial'liste_testimonial'=>$liste_testimonial'aboutCalltoaction'=>$aboutCalltoaction
  99.         'liste_team'=>$liste_team,'aboutDetailteam'=>$aboutDetailteam'aboutPricing'=>$aboutPricing'aboutFaq'=>$aboutFaq,
  100.         'aboutBlog'=>$aboutBlog'liste_faq'=>$liste_faq'liste_blog'=>$liste_blog'aboutIntervention'=>$aboutIntervention,
  101.         'liste_intervention'=>$liste_intervention'liste_produit'=>$liste_produit'liste_service'=>$liste_service'liste_departement'=>$liste_departement));
  102.     }
  103.     public function login(GeneralServicetext $serviceRequest $request)
  104.     {
  105.         $em $this->getDoctrine()->getManager();
  106.         // Si le visiteur est déjà identifié, on le redirige vers l'accueil
  107.         if($this->getUser() != null){ //IS_AUTHENTICATED_REMEMBERED
  108.             return $this->redirect($this->generateUrl('users_user_accueil'));
  109.         }
  110.         //connexion sécurisé user.
  111.         $error_login '';
  112.         $last_username null;
  113.         if($request->getMethod() == 'POST' and $this->getUser() == null){
  114.             if (isset($_POST['_username']) and isset($_POST['_password'])){
  115.                 $repository $em->getRepository(User::class);
  116.                 $user $repository->findOneBy(array('username'=>$_POST['_username']));
  117.                 
  118.                 if($user != null)
  119.                 {
  120.                     if($_POST['_password'] == $service->decrypt($user->getPassword(),$user->getSalt()))
  121.                     {
  122.                         $response $this->guardHandler->authenticateUserAndHandleSuccess(
  123.                             $user,          // the User object you just created
  124.                             $request,
  125.                             $this->authenticator// authenticator whose onAuthenticationSuccess you want to use
  126.                             'main'          // the name of your firewall in security.yaml
  127.                         );
  128.                         //$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
  129.                         //$this->get('security.token_storage')->setToken($token);
  130.                         //$this->get('session')->set('_security_main', serialize($token));
  131.                         // Verifie si le cookie n existe pas
  132.                         if((!isset($_COOKIE["PIDSESSREM"]) or $_COOKIE["PIDSESSREM"] == 'delete') and isset($_POST['_remember_me']) and $_POST['_remember_me'] == true)
  133.                         {
  134.                             // Stock les infos du cookie
  135.                             $cookie_info = array(
  136.                                 'name'  => 'PIDSESSREM',
  137.                                 'value' => $service->encrypt($user->getUsername(),$this->params->get('saltcookies')),
  138.                                 'time'  => time() + (3600 24 360)
  139.                             );
  140.                             // Cree le cookie
  141.                             setCookie($cookie_info['name'], $cookie_info['value'], $cookie_info['time'],'/');
  142.                             setCookie('PIDSESSDUR',$cookie_info['time'], $cookie_info['time'],'/');
  143.                         }
  144.                         $session $this->get('session');
  145.                         $target_link $session->get('_security.welcome.target_path');
  146.                         if($target_link != null and strlen($target_link) > 5)
  147.                         {
  148.                             return $this->redirect($target_link);
  149.                         }else{
  150.                             return $this->redirect($this->generateUrl('users_user_accueil'));
  151.                         }
  152.                     }else{
  153.                         $error_login '<span style="color: red;">Echec: Mot de passe ou Email invalide.</span>';
  154.                         $last_username $_POST['_username'];
  155.                     }
  156.                 }else{
  157.                     $last_username $_POST['_username'];
  158.                 }
  159.             }
  160.         }
  161.         return $this->render($service->getThemeDirectory().'/Users/User/Security/login.html.twig',
  162.         array('last_username' => $last_username,'error'=> $error_login));
  163.     }
  164. }