src/Controller/SecurityController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Security\Core\Security;
  9. class SecurityController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/accessonegato", name="app_accessonegato")
  13.      */
  14.     public function accessonegato(): Response
  15.     {
  16.         return $this->render('security/accessonegato.html.twig', [
  17.             'titolo' => 'Accesso negato'
  18.         ]);
  19.     }
  20.     /**
  21.      * @Route("/login", name="app_login")
  22.      */
  23.     public function login(AuthenticationUtils $authenticationUtilsSecurity $security): Response
  24.     {
  25.         // intercetto eventuali errori di accesso
  26.         $error $authenticationUtils->getLastAuthenticationError();
  27.         if ($security->getUser()) {
  28.             return $this->redirectToRoute("app_home");
  29.         }
  30.         // recupero l'ultimo nomeutente inserito dall'operatore
  31.         $lastUsername $authenticationUtils->getLastUsername();
  32.         return $this->render('security/login.html.twig', [
  33.             'last_username' => $lastUsername,
  34.             'error' => $error,
  35.             'titolo' => ' '
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/logout", name="app_logout")
  40.      */
  41.     public function logout()
  42.     {
  43.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  44.     }
  45. }