<?php
/**
* Controller gérant la sécurité et l'authentification de l'administration Colibi.
*/
namespace App\Controller\Admin;
use App\Service\CityServices;
use App\Service\TraitementData;
use App\Service\TraitementFolder;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Exception;
/**
* Class SecurityController
* @package App\Controller\Admin
*/
class SecurityController extends AbstractController
{
/**
* @var EntityManagerInterface
*/
protected $em;
/**
* @var CityServices
*/
protected $cityServices;
/**
* @var TraitementData
*/
protected $traitementData;
/**
* @var DenormalizerInterface
*/
private $denormalizer;
/**
* SecurityController constructor.
* @param TraitementData $traitementData
* @param EntityManagerInterface $em
* @param CityServices $cityServices
* @param DenormalizerInterface $denormalizer
*/
public function __construct(
TraitementData $traitementData,
EntityManagerInterface $em,
CityServices $cityServices,
DenormalizerInterface $denormalizer
) {
$this->em = $em;
$this->cityServices = $cityServices;
$this->traitementData = $traitementData;
$this->denormalizer = $denormalizer;
}
/**
* Rendu de la page de connexion admin.
*
* @Route("/admin/login", name="app_login")
* @param AuthenticationUtils $authenticationUtils
* @param TraitementFolder $traiteFolder
* @return Response
*/
public function login(AuthenticationUtils $authenticationUtils, TraitementFolder $traiteFolder): Response
{
// $traiteFolder->add(); // Optimization: Removed to avoid heavy filesystem checks on every login page render. This should be handled by a command or deployment script.
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('admin/security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error
]);
}
/**
* Point de sortie de l'application.
* Intercepté par le firewall Symfony.
*
* @Route("/admin/logout", name="app_logout")
* @throws Exception
*/
public function logout(): void
{
throw new Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
}
}