src/UserBundle/Controller/SecurityController.php line 18

Open in your IDE?
  1. <?php
  2. // src/Controller/SecurityController.php
  3. namespace App\UserBundle\Controller;
  4. use App\UserBundle\Form\LoginType;
  5. use Exception;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. use Symfony\Contracts\Service\Attribute\Required;
  12. class SecurityController extends AbstractController
  13. {
  14.     #[Route("/login"name"app_login")]
  15.     public function login(AuthenticationUtils $authenticationUtils): Response
  16.     {
  17.         // get the login error if there is one
  18.         $error $authenticationUtils->getLastAuthenticationError();
  19.         // last username entered by the user
  20.         $lastUsername $authenticationUtils->getLastUsername();
  21.         return $this->render('@UserBundle/Security/login.html.twig', [
  22.             'last_username' => $lastUsername,
  23.             'error'         => $error
  24.         ]);
  25.     }
  26.     #[Route("/logout"name'app_logout')]
  27.     public function logout(): Exception
  28.     {
  29.         // controller can be blank: it will never be executed!
  30.         throw new Exception('Don\'t forget to activate logout in security.yaml');
  31.     }
  32. }