src/Controller/SecurityController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/login", name="app_security_login", methods={"GET", "POST"})
  14.      */
  15.     public function index(AuthenticationUtils $authenticationUtils): Response
  16.     {
  17.         $error $authenticationUtils->getLastAuthenticationError();
  18.         $lastUsername $authenticationUtils->getLastUsername();
  19.         return $this->render('security/index.html.twig', [
  20.             'last_username' => $lastUsername,
  21.             'error'         => $error,
  22.         ]);
  23.     }
  24.     /**
  25.      * @Route("/logout", name="app_security_logout", methods={"GET"})
  26.      */
  27.     public function logout(): void
  28.     {}
  29.     /**
  30.      * @Route("/get-login-token", name="app_security_token", methods={"GET"})
  31.      */
  32.     public function getLoginToken(Request $requestJWTTokenManagerInterface $JWTManager): ?JsonResponse
  33.     {
  34.         if ($request->isXmlHttpRequest()) {
  35.             return $this->json(['data' => $JWTManager->create($this->getUser())]);
  36.         }
  37.         return null;
  38.     }
  39. }