src/Controller/SecurityController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. class SecurityController extends AbstractController
  10. {
  11. /**
  12. * @Route("/login", name="login")
  13. *
  14. * @param AuthenticationUtils $authenticationUtils
  15. * @param Request $request
  16. * @param TranslatorInterface $translator
  17. * @return Response
  18. */
  19. public function login(AuthenticationUtils $authenticationUtils, Request $request, TranslatorInterface $translator): Response
  20. {
  21. if ($this->getUser() !== null) {
  22. return $this->redirectToRoute('index');
  23. }
  24. // If redirected here after timeout logout, add flash now (session is fresh)
  25. if ($request->query->get('timeout')) {
  26. $this->addFlash('info', $translator->trans('login.timeout', [], 'security'));
  27. }
  28. // get the login error if there is one
  29. $error = $authenticationUtils->getLastAuthenticationError();
  30. // last username entered by the user
  31. $lastUsername = $authenticationUtils->getLastUsername();
  32. return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
  33. }
  34. /**
  35. * @Route("/logout", name="logout")
  36. */
  37. public function logout(): void
  38. {
  39. throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  40. }
  41. }