src/Controller/SecurityController.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace App\Controller;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  15. /**
  16.  * Controller used to manage the application security.
  17.  * See https://symfony.com/doc/current/cookbook/security/form_login_setup.html.
  18.  *
  19.  * @author Ryan Weaver <weaverryan@gmail.com>
  20.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  21.  */
  22. class SecurityController extends AbstractController
  23. {
  24.     /**
  25.      * @Route("/login", name="security_login")
  26.      */
  27.     public function login(AuthenticationUtils $helper): Response
  28.     {
  29.         return $this->render('security/login.html.twig', [
  30.             // last username entered by the user (if any)
  31.             'last_username' => $helper->getLastUsername(),
  32.             // last authentication error (if any)
  33.             'error' => $helper->getLastAuthenticationError(),
  34.         ]);
  35.     }
  36.     /**
  37.      * This is the route the user can use to logout.
  38.      *
  39.      * But, this will never be executed. Symfony will intercept this first
  40.      * and handle the logout automatically. See logout in app/config/security.yml
  41.      *
  42.      * @Route("/logout", name="security_logout")
  43.      */
  44.     public function logout(): void
  45.     {
  46.         throw new \Exception('This should never be reached!');
  47.     }
  48. }