src/Controller/SecurityController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends AbstractController
  11. {
  12.     #[Route(path'/connexion'name'app_login')]
  13.     public function login(AuthenticationUtils $authenticationUtils): Response
  14.     {
  15.         if ($this->getUser()) {
  16.             return $this->redirectToRoute('app_user');
  17.         }       
  18.         // get the login error if there is one
  19.         $error $authenticationUtils->getLastAuthenticationError();
  20.         // last username entered by the user
  21.         $lastUsername $authenticationUtils->getLastUsername();
  22.         return $this->render('security/login.html.twig', [
  23.             'last_username' => $lastUsername,
  24.             'error' => $error
  25.         ]);
  26.     }
  27.     #[Route(path'/predec'name'app_pre_logout')]
  28.     public function pre_logout(EntityManagerInterface $entityManagerUserRepository $repo): Response
  29.     {        
  30.         $u $this->getUser()->getUserIdentifier();        
  31.         $user $repo->findByEmail($u); 
  32.         //dd($user);              
  33.         //$user[0]->setNbLogged($user[0]->getNbLogged()-1);
  34.         $user[0]->setIsLogged(false);
  35.         $user[0]->setLastLoginAt(new \DateTimeImmutable());
  36.         $entityManager->persist($user[0]);
  37.         $entityManager->flush();        
  38.         return $this->redirectToRoute('app_logout');
  39.         //throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  40.     }
  41.     
  42.     #[Route(path'/deconnexion'name'app_logout')]
  43.     public function logout(): void
  44.     {
  45.         //throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  46.     }
  47. }