src/Controller/SecurityController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Component\Security\Http\Util\TargetPathTrait;
  9. class SecurityController extends AbstractController
  10. {
  11.     use TargetPathTrait;
  12.     #[Route('/login'name'login')]
  13.     public function login(AuthenticationUtils $authenticationUtilsRequest $request$targetPath null): Response
  14.     {
  15.         // get the login error if there is one
  16.         $error $authenticationUtils->getLastAuthenticationError();
  17.         // last username entered by the user
  18.         $lastUsername $authenticationUtils->getLastUsername();
  19.         if ($targetPath === null) {
  20.             if ($request->get('_target_path') === null) {
  21.                 $this->removeTargetPath($request->getSession(), 'main');
  22.             } else {
  23.                 $targetPath $request->get('_target_path');
  24.             }
  25.         }
  26.         return $this->render('security/login.html.twig', [
  27.             'last_username' => $lastUsername,
  28.             'error'         => $error,
  29.             'targetPath'    => $targetPath,
  30.         ]);
  31.     }
  32.     #[Route('/logout'name'logout')]
  33.     public function logout(): void
  34.     {
  35.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  36.     }
  37. }