diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 7aa253b..4554f63 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -18,8 +18,14 @@ security: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: - lazy: true +# lazy: true provider: app_user_provider + form_login: + login_path: login + check_path: login + enable_csrf: true + logout: + path: logout # activate different ways to authenticate # https://symfony.com/doc/current/security.html#the-firewall @@ -30,7 +36,7 @@ security: # Easy way to control access for large sections of your site # Note: Only the *first* access control that matches will be used access_control: -# - { path: ^/admin, roles: ROLE_ADMIN } + - { path: ^/admin, roles: ROLE_ADMIN } # - { path: ^/profile, roles: ROLE_USER } when@test: diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php new file mode 100644 index 0000000..862ddc2 --- /dev/null +++ b/src/Controller/LoginController.php @@ -0,0 +1,33 @@ +getUser()) { + // return $this->redirectToRoute('target_path'); + // } + + // get the login error if there is one + $error = $authenticationUtils->getLastAuthenticationError(); + // last username entered by the user + $lastUsername = $authenticationUtils->getLastUsername(); + + return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); + } + + #[Route('/logout', name: 'logout')] + public function logout() + { + throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); + } +} diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index f78773a..6487beb 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -36,7 +36,7 @@ class RegistrationController extends AbstractController return $this->redirectToRoute('app_test_test1'); } - return $this->render('registration/register.html.twig', [ + return $this->render('security/register.html.twig', [ 'registrationForm' => $form->createView(), ]); } diff --git a/src/Controller/TestController.php b/src/Controller/TestController.php index ae4ba36..d9f32eb 100644 --- a/src/Controller/TestController.php +++ b/src/Controller/TestController.php @@ -5,12 +5,18 @@ namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; -#[Route('/test')] +//#[Route('/test')] class TestController extends AbstractController { - #[Route('/1')] + #[Route('/test/1')] public function test1() { return $this->render('base/base.html.twig'); } + + #[Route('/')] + public function home() + { + return $this->render('base/base.html.twig'); + } } \ No newline at end of file diff --git a/templates/base/base.html.twig b/templates/base/base.html.twig index 180f8d4..5d41353 100644 --- a/templates/base/base.html.twig +++ b/templates/base/base.html.twig @@ -12,21 +12,23 @@ integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> - {{ encore_entry_link_tags('app') }} +{# {{ encore_entry_link_tags('app') }}#} {% endblock %}
{% include 'base/navbar.html.twig' %}