<?php
namespace App\Controller\Login;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
// https://symfony.com/doc/5.4/security/remember_me.html
// https://dev-fusion.com/2019/11/01/symfony-creer-rapidement-un-projet-de-base-complet-avec-un-espace-utilisateur.html
// https://symfony.com/doc/5.4/security/form_login.html#redirecting-after-failure
class LoginController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function index(AuthenticationUtils $authenticationUtils, Request $request): Response
{
$redirect_path = $request->query->get('redirect_path');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('login/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'target_path' => $redirect_path
]);
}
//https://symfony.com/doc/5.4/security.html
/**
* @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');
}
}