feat: add login page with SecurityController
This commit is contained in:
@@ -18,7 +18,7 @@ class HomepageController extends AbstractController
|
|||||||
private readonly ActorRepository $actorRepository
|
private readonly ActorRepository $actorRepository
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/')]
|
#[Route('/', name: 'app_homepage')]
|
||||||
public function index(SerializerInterface $serializer): Response
|
public function index(SerializerInterface $serializer): Response
|
||||||
{
|
{
|
||||||
// Final actor to be guessed
|
// Final actor to be guessed
|
||||||
|
|||||||
32
src/Controller/SecurityController.php
Normal file
32
src/Controller/SecurityController.php
Normal 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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
27
templates/security/login.html.twig
Normal file
27
templates/security/login.html.twig
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Log in{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="auth-container">
|
||||||
|
<h1>Log in</h1>
|
||||||
|
|
||||||
|
{% if error %}
|
||||||
|
<div class="auth-error">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<label for="inputEmail">Email</label>
|
||||||
|
<input type="email" value="{{ last_username }}" name="_username" id="inputEmail" autocomplete="email" required autofocus>
|
||||||
|
|
||||||
|
<label for="inputPassword">Password</label>
|
||||||
|
<input type="password" name="_password" id="inputPassword" autocomplete="current-password" required>
|
||||||
|
|
||||||
|
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
|
||||||
|
|
||||||
|
<button type="submit">Sign in</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p class="auth-link">No account yet? <a href="{{ path('app_register') }}">Register</a></p>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user