src/Controller/SecurityController.php line 18

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