src/Controller/SecurityController.php line 15

Open in your IDE?
  1. <?php
  2.     namespace App\Controller;
  3.     use RuntimeException;
  4.     use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  5.     use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6.     use Symfony\Component\Routing\Annotation\Route;
  7.     use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8.     class SecurityController extends AbstractController
  9.     {
  10.         #[Route('/login'name'app_login')]
  11.         #[Template]
  12.         public function login(AuthenticationUtils $authenticationUtils): array
  13.         {
  14.             $error $authenticationUtils->getLastAuthenticationError();
  15.             $lastUsername $authenticationUtils->getLastUsername();
  16.             return [
  17.                 'last_username' => $lastUsername,
  18.                 'error'         => $error,
  19.             ];
  20.         }
  21.         /**
  22.          * @throws RuntimeException
  23.          */
  24.         #[Route('/logout'name'app_logout'methods: ['GET'])]
  25.         public function logout(): void
  26.         {
  27.             // controller can be blank: it will never be called!
  28.             throw new RuntimeException('Don\'t forget to activate logout in security.yaml');
  29.         }
  30.     }