login now completely works

This commit is contained in:
overflowerror 2021-01-05 20:01:34 +01:00
parent 2a5e32da2a
commit cd8d17784b
4 changed files with 37 additions and 4 deletions

View file

@ -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

View file

@ -0,0 +1,26 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
/**
* @Route("/", name="app_home")
*/
public function home(): Response
{
if (!$this->isGranted("ROLE_USER")) {
// not logged in
return $this->redirectToRoute("app_login");
}
return $this->render("home/dashboard.html.twig");
}
}

View file

@ -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()

View file

@ -0,0 +1,9 @@
{% extends 'base.html.twig' %}
{% block title %}Home{% endblock %}
{% block body %}
Hi
{% endblock %}