src/Bundles/UserBundle/Controller/SecurityController.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Bundles\UserBundle\Controller;
  4. use App\Bundles\UserBundle\Entity\UserInterface;
  5. use App\Bundles\UserBundle\Form\Type\Auth\LoginForm;
  6. use App\Bundles\UserBundle\Form\Type\Auth\PhoneLoginForm;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  13. class SecurityController extends AbstractController
  14. {
  15.     public function __construct(
  16.         private readonly AuthenticationUtils $authenticationUtils,
  17.     ) {
  18.     }
  19.     #[Route('/login'name'app_login')]
  20.     public function login(): Response
  21.     {
  22.         if ($this->getUser()) {
  23.             return $this->redirectToRoute('app.home');
  24.         }
  25.         $error $this->authenticationUtils->getLastAuthenticationError();
  26.         $_username $this->authenticationUtils->getLastUsername();
  27.         $form $this->createForm(LoginForm::class);
  28.         $form->get('_username')->setData($_username);
  29.         return $this->renderForm('@User/auth/login.html.twig'compact('error''_username''form'));
  30.     }
  31.     #[Route('/login/phone'name'app_login_by_phone')]
  32.     public function phoneLogin(): Response
  33.     {
  34.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_2FA_IN_PROGRESS');
  35.         /** @var UserInterface $user */
  36.         $user $this->getUser();
  37.         $error $this->authenticationUtils->getLastAuthenticationError();
  38.         $form $this->createForm(PhoneLoginForm::class);
  39.         $form->get('_phone')->setData($user->getPhone());
  40.         return $this->renderForm('@User/auth/phone_login.html.twig'compact('error''form'));
  41.     }
  42.     #[Route('/login/redirect'name'app_login_link_redirect')]
  43.     public function redirectLoginLink(Request $request): Response
  44.     {
  45.         $link $request->query->get('link');
  46.         return $this->render('@User/auth/redirect_login.html.twig'compact('link'));
  47.     }
  48.     #[Route('/login/link/check'name'login_link_check')]
  49.     public function loginLink(): void
  50.     {
  51.     }
  52.     #[Route('/logout'name'app_logout')]
  53.     public function logout(): Response
  54.     {
  55.         return new RedirectResponse('/login');
  56.     }
  57. }