src/Controller/SecurityController.php line 13
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route(path: '/login', name: 'login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('dashboard');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
if ($error == "Invalid credentials.") {
$error = "Zugangsdaten ungültig!";
}
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('login/index.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
#[Route(path: '/logout', name: 'logout')]
public function logout(): \Symfony\Component\HttpFoundation\RedirectResponse
{
// redirect to the login page
return $this->redirectToRoute('login');
}
}