<?php
declare(strict_types=1);
namespace App\Bundles\UserBundle\Controller;
use App\Bundles\UserBundle\Entity\UserInterface;
use App\Bundles\UserBundle\Form\Type\Auth\LoginForm;
use App\Bundles\UserBundle\Form\Type\Auth\PhoneLoginForm;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
public function __construct(
private readonly AuthenticationUtils $authenticationUtils,
) {
}
#[Route('/login', name: 'app_login')]
public function login(): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app.home');
}
$error = $this->authenticationUtils->getLastAuthenticationError();
$_username = $this->authenticationUtils->getLastUsername();
$form = $this->createForm(LoginForm::class);
return $this->renderForm('@User/auth/login.html.twig', compact('error', '_username', 'form'));
}
#[Route('/login/phone', name: 'app_login_by_phone')]
public function phoneLogin(): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_2FA_IN_PROGRESS');
/** @var UserInterface $user */
$user = $this->getUser();
$error = $this->authenticationUtils->getLastAuthenticationError();
$form = $this->createForm(PhoneLoginForm::class);
$form->get('_phone')->setData($user->getPhone());
return $this->renderForm('@User/auth/phone_login.html.twig', compact('error', 'form'));
}
#[Route('/login/redirect', name: 'app_login_link_redirect')]
public function redirectLoginLink(Request $request): Response
{
$link = $request->query->get('link');
return $this->render('@User/auth/redirect_login.html.twig', compact('link'));
}
#[Route('/login/link/check', name: 'login_link_check')]
public function loginLink(): void
{
}
#[Route('/logout', name: 'app_logout')]
public function logout(): Response
{
return new RedirectResponse('/login');
}
}