<?php
namespace App\Controller;
use App\Entity\Member;
use Doctrine\Persistence\ManagerRegistry;
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')]
public function login(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $doctrine): Response
{
// error de autenticación (si lo hubo) y último usuario ingresado
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
$user = null;
if ($request->get('new') != 1 && $lastUsername !== '') {
$entity = $doctrine->getRepository(Member::class)->findOneBy(['email' => $lastUsername]);
if (!empty($entity)) {
$user = $entity;
}
}
return $this->render('default/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'user' => $user,
]);
}
#[Route('/login_check', name: 'login_check')]
public function loginCheck(): never
{
// Esta acción no se ejecuta: la ruta la intercepta el firewall de seguridad.
throw new \LogicException('Interceptada por el firewall.');
}
#[Route('/logout', name: 'logout')]
public function logout(): never
{
// Esta acción no se ejecuta: la ruta la intercepta el firewall de seguridad.
throw new \LogicException('Interceptada por el firewall.');
}
}