src/Controller/SecurityController.php line 26

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 Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  8. class SecurityController extends AbstractController
  9. {
  10. private $authenticationUtils;
  11. private $tokenManager;
  12. public function __construct(AuthenticationUtils $authenticationUtils, CsrfTokenManagerInterface $tokenManager = null)
  13. {
  14. $this->authenticationUtils = $authenticationUtils;
  15. $this->tokenManager = $tokenManager;
  16. }
  17. // /**
  18. // * @Route("/login", name="login")
  19. // */
  20. public function loginAction(): Response
  21. {
  22. $error = $this->authenticationUtils->getLastAuthenticationError();
  23. $lastUsername = $this->authenticationUtils->getLastUsername();
  24. $logoPath = $this->getParameter('kernel.project_dir').'/public/img_logo/logo_.png';
  25. $logoExists = file_exists($logoPath);
  26. $csrfToken = $this->tokenManager
  27. ? $this->tokenManager->getToken('authenticate')->getValue()
  28. : null;
  29. return $this->renderLogin([
  30. 'last_username' => $lastUsername,
  31. 'error' => $error,
  32. 'csrf_token' => $csrfToken,
  33. 'logoExists' => $logoExists,
  34. ]);
  35. }
  36. // /**
  37. // * @Route("/logout", name="app_logout")
  38. // */
  39. public function logout(): void
  40. {
  41. throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  42. }
  43. /**
  44. * Renders the login template with the given parameters. Overwrite this function in
  45. * an extended controller to provide additional data for the login template.
  46. */
  47. protected function renderLogin(array $data): Response
  48. {
  49. return $this->render('security/login_content.html.twig', $data);
  50. }
  51. }