src/Controller/SecurityController.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use App\Services\CustomerManager;
  10. use DateTime;
  11. class SecurityController extends AbstractController
  12. {
  13.     public function __construct(SessionInterface $sessionCustomerManager $customerManager)
  14.     {
  15.         $this->customerManager $customerManager;
  16.         $this->session $session;
  17.     }
  18.     /**
  19.      * @Route("/login", name="login")
  20.      */
  21.     public function login(
  22.         AuthenticationUtils $authenticationUtils,
  23.         Request $request,
  24.         SessionInterface $session
  25.     ): Response {
  26.         if (isset($_GET["ics"])) {
  27.             $this->session->set("ics"$_GET["ics"]);
  28.         }
  29.         if (isset($_GET["new"])) 
  30.         {
  31.             $this->session->set("new",$_GET["new"]);
  32.         } 
  33.         if (isset($_GET["f"])) 
  34.         {
  35.             $this->session->set("f",$_GET["f"]);
  36.         } 
  37.         if (isset($_GET["em"])) 
  38.         {
  39.             $this->session->set("em",$_GET["em"]);
  40.         } 
  41.         $http_referer explode("/"$request->server->get("HTTP_REFERER"));
  42.         $session->set("Http_referer"$http_referer);
  43.         if (isset($http_referer[3]) && isset($http_referer[4])) { 
  44.             if ($this->getUser() && $this->customerManager->getIdCustomerByEmail($this->getUser()->getEmail()) && !$this->getUser()->getIdCustomer() ) 
  45.             {
  46.                return $this->redirectToRoute("order_processing");
  47.             }
  48.             if (
  49.                 $this->getUser() != null &&
  50.                 $this->getUser()->getId() != null &&
  51.                 !is_int($this->getUser()->getIdCustomer()) &&
  52.                 strpos(
  53.                     "/catalog/panier/",
  54.                     "/" $http_referer[3] . "/" $http_referer[4] . "/"
  55.                 ) !== false
  56.             ) {
  57.             } elseif (
  58.                 $this->getUser() != null &&
  59.                 $this->getUser()->getId() != null && ( is_int($this->getUser()->getIdCustomer()) &&
  60.                 strpos(
  61.                     "/catalog/panier/",
  62.                     "/" $http_referer[3] . "/" $http_referer[4] . "/"
  63.                 ) !== false
  64.             )) {
  65.                 return $this->redirectToRoute("order_processing");
  66.             } elseif (
  67.                 $this->getUser() != null &&
  68.                 $this->getUser()->getId() != null
  69.             ) { 
  70.                 return $this->redirectToRoute("backend_my_account");
  71.             }
  72.         }
  73.         if (
  74.             $this->getUser() &&
  75.             $this->getUser()->getRoles()[0] == "ROLE_CUSTOMER"
  76.         ) {
  77.             $formation $startDate $idCourseSession "";
  78.             if (isset($_GET["f"])) {
  79.                 $formation $_GET["f"];
  80.             }
  81.             if (isset($_GET["sd"])) 
  82.             {
  83.                 $startDate $_GET["sd"];
  84.             }
  85.             if (isset($_GET["ics"])) {
  86.                 $idCourseSession $_GET["ics"];
  87.                 $this->session->set("ics"$_GET["ics"]);
  88.             } 
  89.             
  90.             ///update 02/11/22
  91.            ////************************
  92.             if(isset($_GET["f"])&&isset($_GET["sd"]))
  93.             {
  94.                 if(!null == $this->customerManager->hasCompanyName($this->getUser()->getIdCustomer()))
  95.                 return $this->redirectToRoute("register_information",[
  96.                     "origin" => "?=0",
  97.                 "f" =>  $_GET["f"],
  98.                 "sd" =>  $_GET["sd"],
  99.                "ics" =>  $_GET["ics"],
  100.                 ]);
  101.                 else
  102.                     return $this->redirectToRoute("catalog_participant", [
  103.                     "origin" => "?=0",
  104.                     "f" => $formation,
  105.                     "sd" => $startDate,
  106.                     "ics" => $idCourseSession,
  107.                 ]);
  108.             }
  109.             ///END update 02/11/22
  110.           //  else 
  111.             /*{
  112.                 return $this->redirectToRoute("catalog_participant", [
  113.                     "origin" => "?=0",
  114.                     "f" => $formation,
  115.                     "sd" => $startDate,
  116.                     "ics" => $idCourseSession,
  117.                 ]);
  118.             }*/
  119.             /////**********************
  120.         }
  121.         // get the login error if there is one
  122.         $error $authenticationUtils->getLastAuthenticationError();
  123.         // last username entered by the user
  124.         $lastUsername $authenticationUtils->getLastUsername();
  125.         if ($request->query->get("mailNoValid")) {
  126.             $this->addFlash("alert""Merci de valider votre adresse mail.");
  127.         }
  128.         if (isset($_GET["em"])) {
  129.             $_email base64_decode($_GET["em"]);
  130.         }
  131.         if (isset($_GET["exist"])) {
  132.             $exist $_GET["exist"];
  133.         }
  134.         return $this->render("acoa/security/login.html.twig", [
  135.             "last_username" => $lastUsername,
  136.             "error" => $error,
  137.             "_email" => isset($_email) ? $_email null,
  138.             "exist" => isset($exist) ? $exist 1,
  139.         ]);
  140.     }
  141.     /**
  142.      * @Route("/logout", name="app_logout")
  143.      */
  144.     public function logout(): void
  145.     {
  146.         throw new \LogicException(
  147.             "This method can be blank - it will be intercepted by the logout key on your firewall."
  148.         );
  149.     }
  150. }