src/Controller/Login/LoginController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Login;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. // https://symfony.com/doc/5.4/security/remember_me.html
  9. // https://dev-fusion.com/2019/11/01/symfony-creer-rapidement-un-projet-de-base-complet-avec-un-espace-utilisateur.html
  10. // https://symfony.com/doc/5.4/security/form_login.html#redirecting-after-failure
  11. class LoginController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/login", name="app_login")
  15.      */
  16.     public function index(AuthenticationUtils $authenticationUtilsRequest $request): Response
  17.     {
  18.         $redirect_path $request->query->get('redirect_path');
  19.         // get the login error if there is one
  20.         $error $authenticationUtils->getLastAuthenticationError();
  21.         // last username entered by the user
  22.         $lastUsername $authenticationUtils->getLastUsername();
  23.         return $this->render('login/login.html.twig', [
  24.             'last_username' => $lastUsername,
  25.             'error'         => $error,
  26.             'target_path'   => $redirect_path
  27.         ]);
  28.     }
  29.     //https://symfony.com/doc/5.4/security.html
  30.     /**
  31.      * @Route("/logout", name="app_logout", methods={"GET"})
  32.      */
  33.     public function logout(): void
  34.     {
  35.         // controller can be blank: it will never be called!
  36.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  37.     }
  38. }