<?php
namespace App\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Annotations as OA;
use App\Form\LoginType;
use App\Entity\AdUser;
class LoginController extends AbstractController
{
private $em;
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}
/**
* @Route("/", name="home")
*/
public function index(AuthenticationUtils $authenticationUtils)
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
$form = $this->createForm(LoginType::class);
return $this->render('homepage/index.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'form' => $form->createView()
]);
}
/**
* @Route("/utente/is_logged_in", name="is_logged_in", methods="POST", options={"expose"=true})
*/
public function is_logged_in(Request $request)
{
$corretto = false;
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
$corretto = true;
}
return new JsonResponse(['loggato' => $corretto]);
}
/**
* @Route("/logout", name="logout")
*/
public function logout()
{
}
/**
*
* Autenticazione
*
* Ritorna il token JWT
*
* @OA\Response(response=200, description="Ritorna il token JWT")
* @OA\RequestBody(@OA\JsonContent(type="object", example={"username":"", "password":""}))
*
* @Route("/api/login_check", name="login_check", methods="POST", options={"expose"=true})
*/
public function login_check()
{
}
}