<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils, Request $request): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
if (!empty($request->server->get('HTTP_REFERER')) && strpos($request->server->get('HTTP_REFERER'), 'reservation') !== false) {
return $this->render('security/login_reservation.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'redirect' => $request->query->get('redirect') ?? 'reservation'
]);
}
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'redirect' => $request->query->get('redirect') ?? null
]);
}
/**
* @Route("/logout", name="app_logout", methods={"GET"}, options={"expose"=true})
*/
public function logout()
{
// controller can be blank: it will never be executed!
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
}