<?php
namespace App\Controller;
use App\Controller\Api\Service\ProfilerService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
final class DefaultController extends AbstractController
{
public const INITIAL_ROUTE = 'dashboard';
public const LOGIN_ROUTE = 'app_login';
/**
* @Route("/test", name="app_test" )
*/
public function test ():JsonResponse
{
return $this->json([
"message" => "Success",
"session" => $this->getUser()->getUserIdentifier()
], Response::HTTP_OK );
}
/**
* @Route("/{react_routing}", priority="-1", name="indexs", defaults={"react_routing": null}, methods={"POST", "GET"}, requirements={"react_routing"=".+"})
*/
public function index():Response
{
return $this->render('base.html.twig');
}
/**
* Layout login same path AuthController/login (api_auth_login_v2)
* @Route("/login", name="app_login")
* @param ProfilerService $profilerService
* @return Response
*/
public function login(ProfilerService $profilerService): Response{
if(!is_null($profilerService->authenticated())){
if($url = $profilerService->redirectToLastVisited()){
return $this->redirect($url);
}
return $this->redirectToRoute(self::INITIAL_ROUTE);
}
return $this->render('security/index.html.twig');
}
/**
* Layout logout same path AuthController/logout (api_auth_logout)
* @Route("/logout", name="app_logout")
*/
public function logout(): Response
{
return $this->redirectToRoute('app_login');
}
}