src/Controller/SecurityController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Form\Type\LoginFormType;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/login", name="app_login")
  12.      */
  13.     public function login(AuthenticationUtils $authenticationUtils): Response
  14.     {
  15.         if ($this->getUser()) {
  16.             return $this->redirectToRoute('target_path');
  17.         }
  18.         // get the login error if there is one
  19.         $error $authenticationUtils->getLastAuthenticationError();
  20.         // last username entered by the user
  21.         $lastUsername $authenticationUtils->getLastUsername();
  22.         return $this->render(
  23.             'security/login.html.twig',
  24.             [
  25.                 'last_username' => $lastUsername,
  26.                 'error' => $error,
  27.             ]
  28.         );
  29.     }
  30.     protected function createLoginForm($lastUsername)
  31.     {
  32.         return $this->get('form.factory')->createNamed(
  33.             '',
  34.             LoginFormType::class,
  35.             null,
  36.             [
  37.                 'method' => 'POST',
  38.                 'action' => $this->generateUrl('cocorico_admin_check'),
  39.                 'username' => $lastUsername,
  40.             ]
  41.         );
  42.     }
  43.     /**
  44.      * Login check
  45.      *
  46.      * @Route("/login-check", name="cocorico_admin_check")
  47.      *
  48.      * @throws RuntimeException
  49.      */
  50.     public function checkAction()
  51.     {
  52.         throw new \LogicException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
  53.     }
  54.     /**
  55.      * @Route("/logout", name="app_logout")
  56.      */
  57.     public function logout()
  58.     {
  59.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  60.     }
  61. }