src/Controller/SecurityController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\CategorieElearningRepository;
  4. use App\Repository\SettingRepository;
  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. use Symfony\Component\HttpFoundation\Request;
  10. class SecurityController extends AbstractController
  11. {
  12.     #[Route(path'/connexion'name'app_login')]
  13.     public function login(Request $request,CategorieElearningRepository $categorieElearningRepository,SettingRepository $settingRepository,AuthenticationUtils $authenticationUtils): Response
  14.     {
  15.         // if ($this->getUser()) {
  16.         //     return $this->redirectToRoute('target_path');
  17.         // }
  18.         // get the login error if there is one
  19.         $setting $settingRepository->find(1);
  20.         $error $authenticationUtils->getLastAuthenticationError();
  21.         // last username entered by the user
  22.         $lastUsername $authenticationUtils->getLastUsername();
  23.         $redirectUrl $request->query->get('redirect');
  24.         // Stocker dans la session pour l'utiliser après l'authentification
  25.         if ($redirectUrl) {
  26.             $request->getSession()->set('_security.main.target_path'$redirectUrl);
  27.         }
  28.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error,  'setting'=>$setting,
  29.             'categories'=>$categorieElearningRepository->findAll()]);
  30.     }
  31.     #[Route(path'/logout'name'app_logout')]
  32.     public function logout(): void
  33.     {
  34.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  35.     }
  36. }