src/Controller/SecurityController.php line 26
<?phpnamespace App\Controller;use App\Repository\UserRepository;use Doctrine\ORM\EntityManagerInterface;use App\Form\ResetPasswordRequestFormType;use Symfony\Bridge\Twig\Mime\TemplatedEmail;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\Mailer\MailerInterface;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;class SecurityController extends AbstractController{private $em;public function __construct(EntityManagerInterface $em){return $this->em = $em;}#[Route(path: '/', name: 'login')]public function login(AuthenticationUtils $authenticationUtils): Response{// if ($this->getUser()) {// return $this->redirectToRoute('target_path');// }// get the login error if there is one$error = $authenticationUtils->getLastAuthenticationError();// last username entered by the user$lastUsername = $authenticationUtils->getLastUsername();return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);}#[Route(path: '/logout', name: 'app_logout')]public function logout(): void{throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');}#[Route('/forgotten_password', name:"forgotten_password")]public function forgottenPassword(Request $request,UserRepository $userRepository,TokenGeneratorInterface $tokenGeneratorInterface,MailerInterface $mailer,): Response{$form = $this->createForm(ResetPasswordRequestFormType::class);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {# code...//Recuperration de l'email de l'utilisateur$user = $userRepository->findOneByEmail($form->get('email')->getData());//Vérification de l'emailif ($user) {# Géneration de Token$token = $tokenGeneratorInterface->generateToken();//on va persiter notre token dans la base de donnée$user->setResetToken($token);$this->em->persist($user);$this->em->flush();// On génère le lien de renitialisation de mot de passe$url = $this->generateUrl('send_reset_pasword_link',['token'=> $token], UrlGeneratorInterface::ABSOLUTE_URL);$context = compact('url','user');//Envoie d'email$email = (new TemplatedEmail())->from('no-reply@scicawally.com')->to($user->getEmail())->subject("Réinitialisation de mot de passe ")->htmlTemplate("email/resetPassWordLink.html.twig");$mailer->send($email);$this->addFlash('success', "Un lien de reinitialisation vous à été envoyer");}else{$this->addFlash('error', "l'e-mail entrer n'existe pas dans la base de donné ");}}return $this->render('security/reset_password_request.html.twig',['Form'=>$form->createView()]);}}