<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use App\Services\CustomerManager;
use DateTime;
class SecurityController extends AbstractController
{
public function __construct(SessionInterface $session, CustomerManager $customerManager)
{
$this->customerManager = $customerManager;
$this->session = $session;
}
/**
* @Route("/login", name="login")
*/
public function login(
AuthenticationUtils $authenticationUtils,
Request $request,
SessionInterface $session
): Response {
if (isset($_GET["ics"])) {
$this->session->set("ics", $_GET["ics"]);
}
if (isset($_GET["new"]))
{
$this->session->set("new",$_GET["new"]);
}
if (isset($_GET["f"]))
{
$this->session->set("f",$_GET["f"]);
}
if (isset($_GET["em"]))
{
$this->session->set("em",$_GET["em"]);
}
$http_referer = explode("/", $request->server->get("HTTP_REFERER"));
$session->set("Http_referer", $http_referer);
if (isset($http_referer[3]) && isset($http_referer[4])) {
if ($this->getUser() && $this->customerManager->getIdCustomerByEmail($this->getUser()->getEmail()) && !$this->getUser()->getIdCustomer() )
{
return $this->redirectToRoute("order_processing");
}
if (
$this->getUser() != null &&
$this->getUser()->getId() != null &&
!is_int($this->getUser()->getIdCustomer()) &&
strpos(
"/catalog/panier/",
"/" . $http_referer[3] . "/" . $http_referer[4] . "/"
) !== false
) {
} elseif (
$this->getUser() != null &&
$this->getUser()->getId() != null && ( is_int($this->getUser()->getIdCustomer()) &&
strpos(
"/catalog/panier/",
"/" . $http_referer[3] . "/" . $http_referer[4] . "/"
) !== false
)) {
return $this->redirectToRoute("order_processing");
} elseif (
$this->getUser() != null &&
$this->getUser()->getId() != null
) {
return $this->redirectToRoute("backend_my_account");
}
}
if (
$this->getUser() &&
$this->getUser()->getRoles()[0] == "ROLE_CUSTOMER"
) {
$formation = $startDate = $idCourseSession = "";
if (isset($_GET["f"])) {
$formation = $_GET["f"];
}
if (isset($_GET["sd"]))
{
$startDate = $_GET["sd"];
}
if (isset($_GET["ics"])) {
$idCourseSession = $_GET["ics"];
$this->session->set("ics", $_GET["ics"]);
}
///update 02/11/22
////************************
if(isset($_GET["f"])&&isset($_GET["sd"]))
{
if(!null == $this->customerManager->hasCompanyName($this->getUser()->getIdCustomer()))
return $this->redirectToRoute("register_information",[
"origin" => "?=0",
"f" => $_GET["f"],
"sd" => $_GET["sd"],
"ics" => $_GET["ics"],
]);
else
return $this->redirectToRoute("catalog_participant", [
"origin" => "?=0",
"f" => $formation,
"sd" => $startDate,
"ics" => $idCourseSession,
]);
}
///END update 02/11/22
// else
/*{
return $this->redirectToRoute("catalog_participant", [
"origin" => "?=0",
"f" => $formation,
"sd" => $startDate,
"ics" => $idCourseSession,
]);
}*/
/////**********************
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
if ($request->query->get("mailNoValid")) {
$this->addFlash("alert", "Merci de valider votre adresse mail.");
}
if (isset($_GET["em"])) {
$_email = base64_decode($_GET["em"]);
}
if (isset($_GET["exist"])) {
$exist = $_GET["exist"];
}
return $this->render("acoa/security/login.html.twig", [
"last_username" => $lastUsername,
"error" => $error,
"_email" => isset($_email) ? $_email : null,
"exist" => isset($exist) ? $exist : 1,
]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout(): void
{
throw new \LogicException(
"This method can be blank - it will be intercepted by the logout key on your firewall."
);
}
}