src/Controller/LoginController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Nelmio\ApiDocBundle\Annotation\Model;
  10. use OpenApi\Annotations as OA;
  11. use App\Form\LoginType;
  12. use App\Entity\AdUser;
  13. class LoginController extends AbstractController
  14. {
  15.     private $em;
  16.     public function __construct(EntityManagerInterface $entityManager)
  17.     {
  18.         $this->em = $entityManager;
  19.     }
  20.     /**
  21.      * @Route("/", name="home")
  22.      */
  23.     public function index(AuthenticationUtils $authenticationUtils)
  24.     {
  25.         $error = $authenticationUtils->getLastAuthenticationError();
  26.         $lastUsername = $authenticationUtils->getLastUsername();
  27.         $form = $this->createForm(LoginType::class);
  28.         return $this->render('homepage/index.html.twig', [
  29.             'last_username' => $lastUsername,
  30.             'error' => $error,
  31.             'form' => $form->createView()
  32.         ]);
  33.     }
  34.     /**
  35.      * @Route("/utente/is_logged_in", name="is_logged_in", methods="POST", options={"expose"=true})
  36.      */
  37.     public function is_logged_in(Request $request)
  38.     {
  39.         $corretto = false;
  40.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
  41.             $corretto = true;
  42.         }
  43.         return new JsonResponse(['loggato' => $corretto]);
  44.     }
  45.     /**
  46.      * @Route("/logout", name="logout")
  47.      */
  48.     public function logout()
  49.     {
  50.     }
  51.     /**
  52.      *
  53.      * Autenticazione
  54.      *
  55.      * Ritorna il token JWT
  56.      *
  57.      * @OA\Response(response=200, description="Ritorna il token JWT")
  58.      * @OA\RequestBody(@OA\JsonContent(type="object", example={"username":"", "password":""}))
  59.      *
  60.      * @Route("/api/login_check", name="login_check", methods="POST", options={"expose"=true})
  61.      */
  62.     public function login_check()
  63.     {
  64.     }
  65. }