vendor/dachcom-digital/members/src/MembersBundle/Controller/AuthController.php line 42

Open in your IDE?
  1. <?php
  2. namespace MembersBundle\Controller;
  3. use MembersBundle\Form\Factory\FactoryInterface;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  7. use Symfony\Component\Security\Core\Security;
  8. class AuthController extends AbstractController
  9. {
  10.     protected FactoryInterface $formFactory;
  11.     public function __construct(FactoryInterface $formFactory)
  12.     {
  13.         $this->formFactory $formFactory;
  14.     }
  15.     public function loginAction(Request $request): Response
  16.     {
  17.         $authErrorKey Security::AUTHENTICATION_ERROR;
  18.         $lastUsernameKey Security::LAST_USERNAME;
  19.         $session $request->getSession();
  20.         // last username entered by the user
  21.         $lastUsername $session->get($lastUsernameKey);
  22.         $targetPath $request->get('_target_path'null);
  23.         $failurePath $request->get('_failure_path'null);
  24.         $form $this->formFactory->createUnnamedFormWithOptions([
  25.             'last_username' => $lastUsername,
  26.             '_target_path'  => $targetPath,
  27.             '_failure_path' => $failurePath
  28.         ]);
  29.         // get the error if any (works with forward and redirect -- see below)
  30.         if ($request->attributes->has($authErrorKey)) {
  31.             $error $request->attributes->get($authErrorKey);
  32.         } elseif ($session->has($authErrorKey)) {
  33.             $error $session->get($authErrorKey);
  34.             $session->remove($authErrorKey);
  35.         } else {
  36.             $error null;
  37.         }
  38.         if (!$error instanceof AuthenticationException) {
  39.             $error null// The value does not come from the security component.
  40.         }
  41.         return $this->renderForm('@Members/auth/login.html.twig', [
  42.             'form'          => $form,
  43.             'last_username' => $lastUsername,
  44.             'error'         => $error
  45.         ]);
  46.     }
  47.     public function checkAction(): void
  48.     {
  49.         throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
  50.     }
  51.     public function logoutAction(): void
  52.     {
  53.         throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
  54.     }
  55. }