src/Controller/SecurityController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Member;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends AbstractController
  11. {
  12. #[Route('/login', name: 'login')]
  13. public function login(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $doctrine): Response
  14. {
  15. // error de autenticación (si lo hubo) y último usuario ingresado
  16. $error = $authenticationUtils->getLastAuthenticationError();
  17. $lastUsername = $authenticationUtils->getLastUsername();
  18. $user = null;
  19. if ($request->get('new') != 1 && $lastUsername !== '') {
  20. $entity = $doctrine->getRepository(Member::class)->findOneBy(['email' => $lastUsername]);
  21. if (!empty($entity)) {
  22. $user = $entity;
  23. }
  24. }
  25. return $this->render('default/login.html.twig', [
  26. 'last_username' => $lastUsername,
  27. 'error' => $error,
  28. 'user' => $user,
  29. ]);
  30. }
  31. #[Route('/login_check', name: 'login_check')]
  32. public function loginCheck(): never
  33. {
  34. // Esta acción no se ejecuta: la ruta la intercepta el firewall de seguridad.
  35. throw new \LogicException('Interceptada por el firewall.');
  36. }
  37. #[Route('/logout', name: 'logout')]
  38. public function logout(): never
  39. {
  40. // Esta acción no se ejecuta: la ruta la intercepta el firewall de seguridad.
  41. throw new \LogicException('Interceptada por el firewall.');
  42. }
  43. }