src/Controller/LoginController.php line 20

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