src/Controller/SecurityController.php line 25

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Log;
  4. use App\Entity\User;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  12. class SecurityController extends AbstractController
  13. {
  14.     private EntityManagerInterface $em;
  15.     public function __construct(EntityManagerInterface $em)
  16.     {
  17.         $this->em $em;
  18.     }
  19.     #[Route('/login'name'app_login')]
  20.     public function login(AuthenticationUtils $authenticationUtils): Response
  21.     {
  22.         // if ($this->getUser()) {
  23.         //     return $this->redirectToRoute('target_path');
  24.         // }
  25.         // get the login error if there is one
  26.         $error $authenticationUtils->getLastAuthenticationError();
  27.         // last username entered by the user
  28.         $lastUsername $authenticationUtils->getLastUsername();
  29.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  30.     }
  31.     #[Route('/logout'name'app_logout')]
  32.     public function logout(Request $requestManagerRegistry $doctrine): void
  33.     {
  34. //        dd('here');
  35. //        if ($this->getUser() != null) {
  36. //            // Create log
  37. //            $log = new Log();
  38. //            $log->setCreatedBy($this->getUser());
  39. //            $log->setLevel(1);
  40. //            $log->setTitle("Déconnexion utilisateur");
  41. //            $log->setDescription("L'utilisateur ".$this->getUser()->getUsername()." vient de se déconnecter : ".$this->getUser()->getUsername());
  42. //            $log->setOthers("IP : ".$request->getClientIp()." Others : ".$request->headers->get('User-Agent'));
  43. //            $em = $doctrine->getManager();
  44. //            $em->persist($log);
  45. //            $em->flush();
  46. //        }
  47. //        throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  48.     }
  49. }