src/Controller/SecurityController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\LoginFormType;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends AbstractController
  9. {
  10. #[Route(path: '/login', name: 'user_login')]
  11. public function login(AuthenticationUtils $authenticationUtils): Response
  12. {
  13. if ($this->getUser()) {
  14. return $this->redirectToRoute('home');
  15. }
  16. $form = $this->createForm(LoginFormType::class);
  17. // get the login error if there is one
  18. $error = $authenticationUtils->getLastAuthenticationError();
  19. // last username entered by the user
  20. $lastUsername = $authenticationUtils->getLastUsername();
  21. $form->get('email')->setData(
  22. $lastUsername
  23. );
  24. return $this->render('security/login.html.twig', [
  25. 'loginForm' => $form->createView(),
  26. 'error' => $error
  27. ]);
  28. }
  29. #[Route(path: '/logout', name: 'user_logout')]
  30. public function logout(): never
  31. {
  32. throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  33. }
  34. }