src/Controller/SecurityController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Tickets;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/api/login", name="api_login", methods={"POST"})
  13.      */
  14.     public function loginApi(): JsonResponse
  15.     {
  16.         return new JsonResponse([
  17.             'error' => 'This endpoint is only for login purposes and should be handled by the security system.'
  18.         ], 400);
  19.     }
  20.     /**
  21.      * @Route("/login", name="app_login")
  22.      */
  23.     public function login(AuthenticationUtils $authenticationUtils): Response
  24.     {
  25.         if ($this->getUser()) {
  26.             return $this->redirectToRoute('home');
  27.         }
  28.         // get the login error if there is one
  29.         $error $authenticationUtils->getLastAuthenticationError();
  30.         // last username entered by the user
  31.         $lastUsername $authenticationUtils->getLastUsername();
  32.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error'login' => false]);
  33.     }
  34.     /**
  35.      * @Route("/logout", name="app_logout")
  36.      */
  37.     public function logout(): void
  38.     {
  39.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  40.     }
  41. }