<?php
namespace App\Controller\Admin;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* Class SecurityController
* @package App\Controller\Admin
* @Route(path="/admin", name="admin_")
*/
class SecurityController extends AbstractController
{
/**
* @param AuthenticationUtils $authenticationUtils
* @return Response
* @Route("/login", name="login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
return $this->redirectToRoute('admin_index');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('admin/security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @throws Exception
* @Route("/logout", name="logout")
*/
public function logout(): void
{
throw new Exception('This should never be reached!');
}
}