<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
class SecurityController extends AbstractController
{
private $authenticationUtils;
private $tokenManager;
public function __construct(AuthenticationUtils $authenticationUtils, CsrfTokenManagerInterface $tokenManager = null)
{
$this->authenticationUtils = $authenticationUtils;
$this->tokenManager = $tokenManager;
}
// /**
// * @Route("/login", name="login")
// */
public function loginAction(): Response
{
$error = $this->authenticationUtils->getLastAuthenticationError();
$lastUsername = $this->authenticationUtils->getLastUsername();
$logoPath = $this->getParameter('kernel.project_dir').'/public/img_logo/logo_.png';
$logoExists = file_exists($logoPath);
$csrfToken = $this->tokenManager
? $this->tokenManager->getToken('authenticate')->getValue()
: null;
return $this->renderLogin([
'last_username' => $lastUsername,
'error' => $error,
'csrf_token' => $csrfToken,
'logoExists' => $logoExists,
]);
}
// /**
// * @Route("/logout", name="app_logout")
// */
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
/**
* Renders the login template with the given parameters. Overwrite this function in
* an extended controller to provide additional data for the login template.
*/
protected function renderLogin(array $data): Response
{
return $this->render('security/login_content.html.twig', $data);
}
}