<?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;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Security;
class SecurityController extends AbstractController
{
/**
* @Route("/accessonegato", name="app_accessonegato")
*/
public function accessonegato(): Response
{
return $this->render('security/accessonegato.html.twig', [
'titolo' => 'Accesso negato'
]);
}
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils, Security $security): Response
{
// intercetto eventuali errori di accesso
$error = $authenticationUtils->getLastAuthenticationError();
if ($security->getUser()) {
return $this->redirectToRoute("app_home");
}
// recupero l'ultimo nomeutente inserito dall'operatore
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'titolo' => ' '
]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}