src/Controller/LoginController.php line 17

  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\UserRepository;
  4. use LogicException;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class LoginController extends AbstractController
  10. {
  11.     #[Route(path'/login'name'app_login')]
  12.     public function login(AuthenticationUtils $authenticationUtilsUserRepository $userRepository): Response
  13.     {
  14.         if(count($userRepository->findAll()) == 0)
  15.             return $this->redirectToRoute('app_register');
  16.         if ($this->getUser())
  17.             return $this->redirectToRoute('app_home');
  18.         $error $authenticationUtils->getLastAuthenticationError();
  19.         $lastUsername $authenticationUtils->getLastUsername();
  20.         return $this->render('security/login.html.twig', [
  21.             'last_username' => $lastUsername,
  22.             'error' => $error,
  23.             'avis_maintenance' => false
  24.         ]);
  25.     }
  26.     #[Route(path'/logout'name'app_logout')]
  27.     public function logout(): void
  28.     {
  29.         throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  30.     }
  31. }