|
@@ -0,0 +1,46 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Controller;
|
|
|
+
|
|
|
+use App\Repository\UserRepository;
|
|
|
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
+use Symfony\Component\HttpFoundation\Request;
|
|
|
+use Symfony\Component\HttpFoundation\Response;
|
|
|
+use Symfony\Component\Routing\Attribute\Route;
|
|
|
+use Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface;
|
|
|
+
|
|
|
+class SecurityController extends AbstractController
|
|
|
+{
|
|
|
+ #[Route('/login_check', name: 'login_check')]
|
|
|
+ public function check(): never
|
|
|
+ {
|
|
|
+ throw new \LogicException('This code should never be reached');
|
|
|
+ }
|
|
|
+
|
|
|
+ #[Route('/login', name: 'login')]
|
|
|
+ public function requestLoginLink(LoginLinkHandlerInterface $loginLinkHandler, UserRepository $userRepository, Request $request): Response
|
|
|
+ {
|
|
|
+ // check if form is submitted
|
|
|
+ if ($request->isMethod('POST')) {
|
|
|
+ // load the user in some way (e.g. using the form input)
|
|
|
+ $email = $request->getPayload()->get('email');
|
|
|
+ $user = $userRepository->findOneBy(['email' => $email]);
|
|
|
+
|
|
|
+ if ($user) {
|
|
|
+
|
|
|
+ // create a login link for $user this returns an instance
|
|
|
+ // of LoginLinkDetails
|
|
|
+ $loginLinkDetails = $loginLinkHandler->createLoginLink($user);
|
|
|
+ $loginLink = $loginLinkDetails->getUrl();
|
|
|
+
|
|
|
+ dump($loginLink);
|
|
|
+
|
|
|
+ return $this->render('security/login_link_sent.html.twig');
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // if it's not submitted, render the form to request the "login link"
|
|
|
+ return $this->render('security/request_login_link.html.twig');
|
|
|
+ }
|
|
|
+}
|