src/Controller/SecurityController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. class SecurityController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/login", name="app_login")
  12.      */
  13.     public function login(AuthenticationUtils $authenticationUtils): Response
  14.     {
  15.         //dd($this->getUser());
  16.         if ($this->getUser()) {
  17.             return $this->redirectToRoute('dashboard');
  18.             //return new JsonResponse(array('message' => $this->getUser()->getSessionId()));
  19.         }
  20.         /*
  21.         https://stackoverflow.com/questions/10615363/allow-only-one-connection-on-the-same-login-with-fosuserbundle
  22.         //$has_session = is_file('%kernel.project_dir%/var/sessions/%kernel.environment%'.'sess_'.$user->getSessionId());
  23.         $has_session = is_file('%kernel.project_dir%/var/sessions/%kernel.environment%/text.txt');
  24.         if ($has_session) {
  25.             return new JsonResponse(array('message' => 'exists'));
  26.         } else {
  27.             return new JsonResponse(array('message' => 'not exists'));
  28.         }*/
  29.         // get the login error if there is one
  30.         $error $authenticationUtils->getLastAuthenticationError();
  31.         // last username entered by the user
  32.         $lastUsername $authenticationUtils->getLastUsername();
  33.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  34.     }
  35.     /**
  36.      * @Route("/logout", name="app_logout")
  37.      */
  38.     public function logout(): void
  39.     {
  40.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  41.     }
  42. }