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

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.         return $this->renderForm('@User/auth/login.html.twig'compact('error''_username''form'));
  29.     }
  30.     #[Route('/login/phone'name'app_login_by_phone')]
  31.     public function phoneLogin(): Response
  32.     {
  33.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_2FA_IN_PROGRESS');
  34.         /** @var UserInterface $user */
  35.         $user $this->getUser();
  36.         $error $this->authenticationUtils->getLastAuthenticationError();
  37.         $form $this->createForm(PhoneLoginForm::class);
  38.         $form->get('_phone')->setData($user->getPhone());
  39.         return $this->renderForm('@User/auth/phone_login.html.twig'compact('error''form'));
  40.     }
  41.     #[Route('/login/redirect'name'app_login_link_redirect')]
  42.     public function redirectLoginLink(Request $request): Response
  43.     {
  44.         $link $request->query->get('link');
  45.         return $this->render('@User/auth/redirect_login.html.twig'compact('link'));
  46.     }
  47.     #[Route('/login/link/check'name'login_link_check')]
  48.     public function loginLink(): void
  49.     {
  50.     }
  51.     #[Route('/logout'name'app_logout')]
  52.     public function logout(): Response
  53.     {
  54.         return new RedirectResponse('/login');
  55.     }
  56. }