mirror of
https://github.com/sigmasternchen/MyTube
synced 2025-03-16 05:18:54 +00:00
login now completely works
This commit is contained in:
parent
2a5e32da2a
commit
cd8d17784b
4 changed files with 37 additions and 4 deletions
config/packages
src
templates/home
|
@ -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
|
||||
|
|
26
src/Controller/HomeController.php
Normal file
26
src/Controller/HomeController.php
Normal 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");
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
9
templates/home/dashboard.html.twig
Normal file
9
templates/home/dashboard.html.twig
Normal file
|
@ -0,0 +1,9 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Home{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
Hi
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in a new issue