Task: Deny access to loginform in active sessions

This commit is contained in:
Björn Fromme
2023-09-12 15:08:51 +02:00
parent 69b6a0f395
commit 3739decab8
@@ -2,6 +2,7 @@
namespace App\Controller\Security; namespace App\Controller\Security;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@@ -12,6 +13,12 @@ class LoginController extends AbstractController
#[Route('/login', name: 'app_security_login')] #[Route('/login', name: 'app_security_login')]
public function login(AuthenticationUtils $authenticationUtils): Response 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 // get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError(); $error = $authenticationUtils->getLastAuthenticationError();