src/Controller/SecurityController.php line 20

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. class SecurityController extends AbstractController
  8. {
  9.     /**
  10.      * Display the login page
  11.      *
  12.      * @param AuthenticationUtils $authenticationUtils
  13.      *
  14.      * @return Response template /security/login.html.twig
  15.      */
  16.     #[Route('/login'name'app_login')]
  17.     public function login(AuthenticationUtils $authenticationUtils): Response
  18.     {
  19.          if ($this->getUser()) {
  20.              return $this->redirectToRoute('app_dashboard');
  21.          }
  22.         // get the login error if there is one
  23.         $error $authenticationUtils->getLastAuthenticationError();
  24.         // last username entered by the user
  25.         $lastUsername $authenticationUtils->getLastUsername();
  26.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  27.     }
  28.     /**
  29.      * Logout
  30.      */
  31.     #[Route('/logout'name'app_logout')]
  32.     public function logout(): void
  33.     {
  34.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  35.     }
  36. }