diff --git a/config/packages/security.yaml b/config/packages/security.yaml index ce8542b..5523d1a 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -24,7 +24,7 @@ security: logout: path: app_logout # where to redirect after logout - # target: app_any_route + target: app_login # activate different ways to authenticate # https://symfony.com/doc/current/security.html#firewalls-authentication diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php new file mode 100644 index 0000000..e78cacd --- /dev/null +++ b/src/Controller/HomeController.php @@ -0,0 +1,26 @@ +isGranted("ROLE_USER")) { + // not logged in + return $this->redirectToRoute("app_login"); + } + + return $this->render("home/dashboard.html.twig"); + } +} \ No newline at end of file diff --git a/src/Security/LoginFormAuthenticator.php b/src/Security/LoginFormAuthenticator.php index b823548..3ae64a0 100644 --- a/src/Security/LoginFormAuthenticator.php +++ b/src/Security/LoginFormAuthenticator.php @@ -4,7 +4,6 @@ namespace App\Security; use App\Entity\User; use Doctrine\ORM\EntityManagerInterface; -use Exception; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -96,8 +95,7 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator return new RedirectResponse($targetPath); } - // For example : return new RedirectResponse($this->urlGenerator->generate('some_route')); - throw new Exception('TODO: provide a valid redirect inside ' . __FILE__); + return new RedirectResponse($this->urlGenerator->generate('app_home')); } protected function getLoginUrl() diff --git a/templates/home/dashboard.html.twig b/templates/home/dashboard.html.twig new file mode 100644 index 0000000..ae38124 --- /dev/null +++ b/templates/home/dashboard.html.twig @@ -0,0 +1,9 @@ +{% extends 'base.html.twig' %} + +{% block title %}Home{% endblock %} + +{% block body %} + + Hi + +{% endblock %} \ No newline at end of file