feat: add login page with SecurityController

This commit is contained in:
thibaud-leclere
2026-03-28 13:16:50 +01:00
parent 1720246382
commit 64949d2ec2
3 changed files with 60 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ class HomepageController extends AbstractController
private readonly ActorRepository $actorRepository
) {}
#[Route('/')]
#[Route('/', name: 'app_homepage')]
public function index(SerializerInterface $serializer): Response
{
// Final actor to be guessed

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route('/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app_homepage');
}
return $this->render('security/login.html.twig', [
'last_username' => $authenticationUtils->getLastUsername(),
'error' => $authenticationUtils->getLastAuthenticationError(),
]);
}
#[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.');
}
}