<?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 LoginController extends AbstractController
{
/**
* @Route("/login", name="app_login")
* @param AuthenticationUtils $authenticationUtils
* @return Response
*/
public function index(AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('login/index.html.twig', [
'last_username' => $lastUsername,
'error' => $error
]);
}
/**
* @Route(path="/login_success", name="login_success")
* @return Response
*/
public function loginSuccess(): Response
{
$user = $this->getUser();
if (!$user->isIsSpecial()) {
return $this->redirectToRoute('dashboard');
} else {
return $this->redirectToRoute('app_special_index');
}
}
/**
* @Route("/logout", name="app_logout", methods={"GET"})
* @throws \Exception
*/
public function logout(): void
{
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
}