<?php
namespace App\Controller;
use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="login")
* @param UserRepository $repoUser
* @param Request $request
* @param AuthenticationUtils $authenticationUtils
*
* @return Response
*/
public function login(UserRepository $repoUser, Request $request, AuthenticationUtils $authenticationUtils): Response
{
$session = $request->getSession();
$isComplaint = $request->get("complaint", "0") == "1";
if ($isComplaint && !$session->get("expressComplaintPrice")) {
return $this->redirectToRoute("express_complaint_x_prices");
}
if ($this->getUser()) {
if ($isComplaint) {
return $this->redirectToRoute('express_complaint_register');
} else {
return $this->redirectToRoute('user_home');
}
}
$session = $request->getSession();
$email = $session->get('login_register_email');
if (!$email) {
return $this->redirectToRoute('login_register', ["complaint" => $isComplaint ? "1" : "0"]);
}
if (!$repoUser->findByEmail($email)) {
if ($isComplaint) {
return $this->redirectToRoute('express_complaint_register');
} else {
return $this->redirectToRoute('register');
}
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
if ($isComplaint) {
$session->set("userType", "login");
return $this->render('ExpressComplaint/login.html.twig', [
'email' => $email,
'error' => $error,
'breadcrumbComplaintExpress' => 'express_complaint_login',
'navbarTitle' => $request->getSession()->get('expressComplaintCategoryName'),
'progressValue' => 10,
'userType' => "login",
]);
}
return $this->render('Security/login.html.twig', [
'email' => $email,
'error' => $error
]);
}
/**
* @Route("/logout", name="logout")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}