<?php
namespace App\Controller;
use App\Services\SessionService;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
private SessionService $sessionService;
public function __construct(SessionService $sessionService)
{
$this->sessionService = $sessionService;
}
#[Route('/login', name: 'app_login', methods: ["GET", "POST"])]
public function index(AuthenticationUtils $authenticationUtils,TranslatorInterface $translator): Response
{
$data = $this->sessionService->_getBaseParameters();
if ($data["elligible"]) {
return $this->redirectToRoute('home');
}
if ($data["code"]) {
return $this->redirectToRoute('verify');
}
$data["error"] = $authenticationUtils->getLastAuthenticationError();
$data["last_username"] = $authenticationUtils->getLastUsername();
$data['title'] = $translator->trans('pages.login.title');
return $this->render('Security/login.twig', $data);
}
/**
* @Route("/logout", name="app_logout", methods={"GET"})
*/
public function logout(): void
{
// controller can be blank: it will never be called!
throw new Exception('Don\'t forget to activate logout in security.yaml');
}
}