src/Controller/LoginController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class LoginController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/", name="index")
  12.      */
  13.     public function index(): RedirectResponse
  14.     {
  15.         if (
  16.             is_null($this->getUser())
  17.             || !$this->isGranted('IS_REMEMBERED')
  18.         ) {
  19.             return $this->redirectToRoute('connexion');
  20.         }
  21.         return $this->redirectToRoute('liste_abris');
  22.     }
  23.     /**
  24.      * @Route("/login", name="login")
  25.      */
  26.     public function login(AuthenticationUtils $authenticationUtils): Response
  27.     {
  28.         // get the login error if there is one
  29.         $error $authenticationUtils->getLastAuthenticationError();
  30.         // last username entered by the user
  31.         $lastUsername $authenticationUtils->getLastUsername();
  32.         return $this->render('login/index.html.twig', [
  33.             'controller_name' => 'LoginController',
  34.             'last_username' => $lastUsername,
  35.             'error' => $error,
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/logout", name="logout", methods={"GET"})
  40.      *
  41.      * @throws \Exception
  42.      */
  43.     public function logout()
  44.     {
  45.         // controller can be blank: it will never be executed!
  46.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  47.     }
  48. }