|
@@ -2,8 +2,10 @@
|
|
|
|
|
|
namespace App\Controller;
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
+use App\Form\LoginType;
|
|
use App\Repository\UserRepository;
|
|
use App\Repository\UserRepository;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
+use Symfony\Component\Form\FormError;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Notifier\NotifierInterface;
|
|
use Symfony\Component\Notifier\NotifierInterface;
|
|
@@ -28,37 +30,39 @@ class SecurityController extends AbstractController
|
|
Request $request
|
|
Request $request
|
|
): Response
|
|
): 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]);
|
|
|
|
|
|
+ $form = $this->createForm(LoginType::class);
|
|
|
|
+ $form->handleRequest($request);
|
|
|
|
|
|
|
|
+ if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
+ $email = $form->get('email')->getData();
|
|
|
|
+ $user = $userRepository->findOneBy(['email' => $email]);
|
|
if ($user) {
|
|
if ($user) {
|
|
-
|
|
|
|
- // create a login link for $user this returns an instance
|
|
|
|
- // of LoginLinkDetails
|
|
|
|
- $loginLinkDetails = $loginLinkHandler->createLoginLink($user);
|
|
|
|
- $loginLink = $loginLinkDetails->getUrl();
|
|
|
|
-
|
|
|
|
- //dump($loginLink);
|
|
|
|
- // create a notification based on the login link details
|
|
|
|
- $notification = new LoginLinkNotification(
|
|
|
|
- $loginLinkDetails,
|
|
|
|
- 'Bienvenue sur One Movie One Week' // email subject
|
|
|
|
- );
|
|
|
|
- // create a recipient for this user
|
|
|
|
- $recipient = new Recipient($user->getEmail());
|
|
|
|
|
|
|
|
- // send the notification to the user
|
|
|
|
- $notifier->send($notification, $recipient);
|
|
|
|
|
|
+ $loginLinkDetails = $loginLinkHandler->createLoginLink($user);
|
|
|
|
+ $loginLink = $loginLinkDetails->getUrl();
|
|
|
|
|
|
- return $this->render('security/login_link_sent.html.twig');
|
|
|
|
|
|
+ $notification = new LoginLinkNotification(
|
|
|
|
+ $loginLinkDetails,
|
|
|
|
+ 'Bienvenue sur One Movie One Week' // email subject
|
|
|
|
+ );
|
|
|
|
+ $recipient = new Recipient($user->getEmail());
|
|
|
|
+ $notifier->send($notification, $recipient);
|
|
|
|
|
|
|
|
+ return $this->redirectToRoute('app_login_sent');
|
|
}
|
|
}
|
|
|
|
+ $form->get('email')->addError(new FormError('Aucun utilisateur avec cet email'));
|
|
}
|
|
}
|
|
-
|
|
|
|
// if it's not submitted, render the form to request the "login link"
|
|
// if it's not submitted, render the form to request the "login link"
|
|
- return $this->render('security/request_login_link.html.twig');
|
|
|
|
|
|
+ return $this->render('security/request_login_link.html.twig', [
|
|
|
|
+ 'form' => $form
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #[Route('/sent', name: 'app_login_sent')]
|
|
|
|
+ public function loginSent(): Response
|
|
|
|
+ {
|
|
|
|
+ return $this->render('security/login_link_sent.html.twig', [
|
|
|
|
+ 'message' => 'Lien de connexion envoyé avec succès.',
|
|
|
|
+ ]);
|
|
}
|
|
}
|
|
}
|
|
}
|