From dd78bf42e314f09b7383e56c74ee5408ebec3987 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Fri, 5 Jun 2026 18:41:50 +0000 Subject: [PATCH] Add proper auth pages --- config/packages/security.yaml | 13 +++++++++---- src/Controller/AccountController.php | 12 +++++++++--- templates/account/login.html.twig | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 templates/account/login.html.twig diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 68f1e5c..a9ace22 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -19,17 +19,22 @@ security: main: lazy: true provider: app_user_provider - + form_login: + login_path: app_login + check_path: app_login + logout: + path: app_logout # Activate different ways to authenticate: # https://symfony.com/doc/current/security.html#the-firewall # https://symfony.com/doc/current/security/impersonating_user.html # switch_user: true - # Note: Only the *first* matching rule is applied + # Note: Only the *first* matching rule is applied access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } + - {path: ^/account/login, roles: PUBLIC_ACCESS} + - {path: ^/account/register, roles: PUBLIC_ACCESS} + - {path: ^/, roles: ROLE_USER} when@test: security: diff --git a/src/Controller/AccountController.php b/src/Controller/AccountController.php index 2b6029f..34dae8e 100644 --- a/src/Controller/AccountController.php +++ b/src/Controller/AccountController.php @@ -16,7 +16,7 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; class AccountController extends AbstractController { - #[Route('/account/login')] + #[Route('/account/login', name: 'app_login')] public function login(AuthenticationUtils $authUtils): Response { $error = $authUtils->getLastAuthenticationError(); @@ -28,7 +28,7 @@ class AccountController extends AbstractController ]); } - #[Route('/account/register')] + #[Route('/account/register', name: 'app_register')] public function register( Request $request, UserPasswordHasherInterface $passwordHasher, @@ -58,11 +58,17 @@ class AccountController extends AbstractController $em->persist($user); $em->flush(); - return $this->redirectToRoute('app_account_login'); + return $this->redirectToRoute('app_login'); } return $this->render('account/register.html.twig', [ 'form' => $form, ]); } + + #[Route('/account/logout', name: 'app_logout')] + public function logout(): void + { + throw new \LogicException('This should never be reached.'); + } } diff --git a/templates/account/login.html.twig b/templates/account/login.html.twig new file mode 100644 index 0000000..fc9221a --- /dev/null +++ b/templates/account/login.html.twig @@ -0,0 +1,23 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Log in

+ + {% if error %} +
{{ error.messageKey|trans(error.messageData, 'security') }}
+ {% endif %} + +
+ + + + + + + + + +
+ +

No account yet? Register

+{% endblock %}