From 3739decab8a92983ddf726d83471a145de49b4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 12 Sep 2023 15:08:51 +0200 Subject: [PATCH] Task: Deny access to loginform in active sessions --- src/Controller/Security/LoginController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Controller/Security/LoginController.php b/src/Controller/Security/LoginController.php index 365ecc6..de709d0 100644 --- a/src/Controller/Security/LoginController.php +++ b/src/Controller/Security/LoginController.php @@ -2,6 +2,7 @@ namespace App\Controller\Security; +use App\Entity\User; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -12,6 +13,12 @@ class LoginController extends AbstractController #[Route('/login', name: 'app_security_login')] public function login(AuthenticationUtils $authenticationUtils): Response { + // redirect to default route in case of active session + if (null !== $user = $this->getUser()) { + /** @var User $user */ + return $this->redirectToRoute($user->getDefaultRoute()); + } + // get the login error if there is one $error = $authenticationUtils->getLastAuthenticationError();