Repository URL to install this package:
|
Version:
6.2.10 ▾
|
<?php
namespace DigitalAscetic\BaseUserBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Twig\Environment;
class SecurityController
{
/** @var CsrfTokenManagerInterface */
private $csrfTokenManager;
/** @var AuthenticationUtils */
private $authenticationUtils;
/** @var Environment $twig */
private Environment $twig;
/**
* SecurityController constructor.
* @param AuthenticationUtils $authenticationUtils
* @param CsrfTokenManagerInterface|null $csrfTokenManager
*/
public function __construct(
Environment $twig,
AuthenticationUtils $authenticationUtils,
CsrfTokenManagerInterface $csrfTokenManager = null,
) {
$this->authenticationUtils = $authenticationUtils;
$this->csrfTokenManager = $csrfTokenManager;
$this->twig = $twig;
}
public function login()
{
// get the login error if there is one
$error = $this->authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $this->authenticationUtils->getLastUsername();
$csrfToken = $this->csrfTokenManager?->getToken('authenticate')->getValue();
return new Response($this->twig->render(
'@DigitalAsceticBaseUser/security/login.html.twig',
[
'last_username' => $lastUsername,
'error' => $error,
'csrfToken' => $csrfToken,
]
));
}
public function check()
{
throw new \RuntimeException(
'You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.'
);
}
public function logout()
{
// controller can be blank: it will never be executed!
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
}