src/Controller/SecurityController.php line 11

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\Security\Http\Authentication\AuthenticationUtils;
  6. class SecurityController extends AbstractController
  7. {
  8.     public function login(AuthenticationUtils $authenticationUtils): Response
  9.     {
  10.         //If the user is logged and
  11.         if ($this->getUser() && $this->getUser()->getActive() == true) {
  12.             return $this->redirectToRoute('app_index');
  13.         }
  14.         //If the user is not active, redirects to logout
  15.         if ($this->getUser() && $this->getUser()->getActive() == false) {
  16.             return $this->redirectToRoute('app_logout');
  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', ['last_username' => $lastUsername'error' => $error]);
  23.     }
  24.     public function logout()
  25.     {
  26.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  27.     }
  28. }