vendor/excelwebzone/symfony-admin-bundle/src/Controller/SecurityController.php line 39

Open in your IDE?
  1. <?php
  2. namespace EWZ\SymfonyAdminBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Core\Security;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Twig\Environment as TwigEnvironment;
  9. /**
  10.  * Controller used to manage the application security.
  11.  * See https://symfony.com/doc/current/security/form_login_setup.html.
  12.  */
  13. class SecurityController
  14. {
  15.     /** @var AuthenticationUtils */
  16.     private $helper;
  17.     /** @var TwigEnvironment */
  18.     private $twig;
  19.     /**
  20.      * @param AuthenticationUtils $helper
  21.      * @param TwigEnvironment     $twig
  22.      */
  23.     public function __construct(AuthenticationUtils $helperTwigEnvironment $twig)
  24.     {
  25.         $this->helper $helper;
  26.         $this->twig $twig;
  27.     }
  28.     /**
  29.      * @Route("/login", name="security_login")
  30.      *
  31.      * @return Response
  32.      */
  33.     public function login(Request $request): Response
  34.     {
  35.         // last authentication error (if any)
  36.         if ($error $this->helper->getLastAuthenticationError()) {
  37.             $request->getSession()->getFlashBag()->add('error'$error->getMessage());
  38.         }
  39.         $content $this->twig->render('@SymfonyAdmin/security/login.html.twig', [
  40.             // last username entered by the user (if any)
  41.             'last_username' => $this->helper->getLastUsername(),
  42.         ]);
  43.         return Response::create($content);
  44.     }
  45.     /**
  46.      * This is the route the user can use to logout.
  47.      *
  48.      * But, this will never be executed. Symfony will intercept this first
  49.      * and handle the logout automatically. See logout in config/packages/security.yaml
  50.      *
  51.      * @Route("/logout", name="security_logout")
  52.      */
  53.     public function logout(): void
  54.     {
  55.         throw new \Exception('This should never be reached!');
  56.     }
  57. }