src/Controller/DefaultController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\UserService;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class DefaultController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/default", name="default")
  13.      */
  14.     public function index(): Response
  15.     {
  16.         return $this->render('default/index.html.twig');
  17.     }
  18.     /**
  19.      * @Route("/login", name="main_login")
  20.      */
  21.     public function login(AuthenticationUtils $authenticationUtils): Response
  22.     {
  23.         $error $authenticationUtils->getLastAuthenticationError();
  24.         $lastUsername $authenticationUtils->getLastUsername();
  25.         return $this->render('login.html.twig', [
  26.             'last_username' => $lastUsername,
  27.             'error' => $error,
  28.         ]);
  29.     }
  30.     /**
  31.      * @Route("/logout", name="main_logout")
  32.      */
  33.     public function logout(): void
  34.     {
  35.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  36.     }
  37.     /**
  38.      * @Route("/user-logged", name="user_logged", methods={"GET"})
  39.      */
  40.     public function userLogged(UserService $userService){
  41.         return new Response(json_encode([
  42.             'result' => 'OK',
  43.             'data' => $userService->getCurrentUser(),
  44.         ]));
  45.     }
  46. }