src/Controller/LoginController.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Blocked;
  4. use App\Repository\BlockedRepository;
  5. use App\Repository\UserRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
  11. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  12. class LoginController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/", name="app_login")
  16.      */
  17.     public function login(Request $request,AuthenticationUtils $authenticationUtilsUserRepository $userRepositoryBlockedRepository $blockedRepository): Response
  18.     {
  19.         // get the login error if there is one
  20.         $error $authenticationUtils->getLastAuthenticationError();
  21.         // last username entered by the user
  22.         $lastUsername $authenticationUtils->getLastUsername();
  23.         if ($this->getUser()) {
  24.             $test false;
  25.             $blocked $blockedRepository->findOneBy(['User'=>$this->getUser()]);
  26.             if ($blocked != null) {
  27.                 if($blocked->getStatut() == "bloquer"){
  28.                     throw new CustomUserMessageAccountStatusException("Votre compte est bloqué merci de contacter votre administrateur.");
  29.                 }else{
  30.                     return $this->redirectToRoute('back_office');
  31.                 }
  32.             }
  33.             else{
  34.                 return $this->redirectToRoute('back_office');
  35.             }
  36.         }
  37.         else{
  38.             $test true;
  39.             //dd($this->getParameter("login_throttling"));
  40.         }
  41.         
  42.         $blocked $blockedRepository->findOneBy(['mail'=>$lastUsername]);
  43.         if ($blocked != null) {
  44.             if($blocked->getStatut() == "bloquer"){
  45.                 $error = new CustomUserMessageAccountStatusException("Votre compte est bloqué merci de contacter votre administrateur.");
  46.             }
  47.         }
  48.         //var_dump($lastUsername);
  49.         if ($error != null) {
  50.             if($error->getMessage() == ""){
  51.                 $element $blockedRepository->findBy(['mail' => $lastUsername]);
  52.                 $blocked = new Blocked();
  53.                 $user $userRepository->findOneBy(['email'=>$lastUsername]);
  54.                 //dd($element);
  55.                 if ($element == []) {
  56.                     $blocked->setMail($lastUsername);
  57.                     $blocked->setStatut("bloquer");
  58.                     $blocked->setUser($user);
  59.                     $blocked->setIpAdress($request->server->get("REMOTE_ADDR"));
  60.                     $entityManager $this->getDoctrine()->getManager();
  61.                     $entityManager->persist($blocked);
  62.                     $entityManager->flush();
  63.                     $error = new CustomUserMessageAccountStatusException("Votre compte est bloqué merci de contacter votre administrateur.");
  64.                 }
  65.             };
  66.         }
  67.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error'test' => $test'notification'=> null,]);
  68.     }
  69.     /**
  70.      * @Route("/logout", name="app_logout")
  71.      */
  72.     public function logout(): void
  73.     {
  74.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  75.     }
  76. }