src/Controller/SecurityController.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\IpOk;
  4. use App\Helper\Tools;
  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\Session\SessionInterface;
  10. class SecurityController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/login", name="app_login")
  14.      * @Route("/login/{slug}", name="app_login_slug")
  15.      */
  16.     public function login(AuthenticationUtils $authenticationUtilsSessionInterface $session$slug false): Response
  17.     {
  18.         if ($_SERVER['HTTP_HOST'] == 'share4.kelkii.com' || $_SERVER['HTTP_HOST'] == 'share.kelkii.com') {
  19.             header("Location: https://www.kelkii.com/");
  20.             exit;
  21.         }
  22.         if ($slug) {
  23.             $em $this->getDoctrine()->getManager();
  24.             $ipok $em->getRepository(IpOk::class)->findOneBy(['slug' => $slug'ip' => $_SERVER['REMOTE_ADDR']]);
  25.             if(!$ipok) {
  26.                 $this->get('session')->getFlashBag()->add('error''404 dude !');
  27.                 return $this->redirectToRoute('app_login');
  28.             }
  29.             $ipok->setUpdateDate(new \DateTime());
  30.             $ipok->setValid(1);
  31.             $em->persist($ipok);
  32.             $em->flush();
  33.             return $this->redirectToRoute('app_login');
  34.         }
  35.         $timeout 0;
  36.         if ($this->getUser()) {
  37.             return $this->redirectToRoute('homepage');
  38.         }
  39.         // get the login error if there is one
  40.         $error $authenticationUtils->getLastAuthenticationError();
  41.         // last username entered by the user
  42.         $lastUsername $authenticationUtils->getLastUsername();
  43.         if($error) {
  44.             $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' "https" "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  45.             Tools::sendErrorToKelkii($actual_linkurlencode('Erreur de connexion pour l\'utilisateur '.$lastUsername), Tools::getUserIpAddr());
  46.             $timeout $session->get('login-error-timeout') + 10;
  47.             $session->set('login-error-timeout'$timeout);
  48.             sleep($timeout);
  49.         } else {
  50.             $session->set('login-error-timeout'0);
  51.         }
  52.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error'timeout' => $timeout]);
  53.     }
  54.     /**
  55.      * @Route("/logout", name="app_logout")
  56.      */
  57.     public function logout(): void
  58.     {
  59.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  60.     }
  61. }