src/Controller/GSSecurityController.php line 20

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