src/Controller/MdpController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Component\Mailer\MailerInterface;
  9. use Symfony\Component\Mime\Email;
  10. use Symfony\Component\Mime\Address;
  11. use App\Repository\UserRepository;
  12. use App\Form\MotDePasseType;
  13. class MdpController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/reset-password", name="reset_password")
  17.      */
  18.     public function resetpassword(UserRepository $userRepositoryRequest $requestEntityManagerInterface $emMailerInterface $mailer): Response
  19.     {
  20.         $motDePasseOublieForm $this->createForm(MotDePasseType::class);
  21.         $motDePasseOublieForm->handleRequest($request);
  22.         if ($motDePasseOublieForm->isSubmitted() && $motDePasseOublieForm->isValid()) {
  23.             if (($user $userRepository->findOneByEmail($motDePasseOublieForm->get('email')->getData())) != null) {
  24.                 $alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
  25.                 'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',
  26.                 'W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
  27.                 $password "";
  28.                 for ($i 0$i 12$i++) {
  29.                     $n Rand(0count($alphabet)-1);
  30.                     $password .= $alphabet[$n];
  31.                 }
  32.                 $user->setPassword($password);
  33.                 $em->persist($user);
  34.                 $em->flush($user);
  35.                 
  36.                 $email = (new Email())
  37.                 ->from(new Address('noreply@lfpl.fr''Déclaration LFPL'))
  38.                 ->to($user->getEmail())
  39.                 ->subject('[LFPL Déclaration Frais Déplacement] Nouveau Mot de Passe')
  40.                 ->embedFromPath($this->getParameter('img_directory').'signature.jpg''signature')
  41.                 ->html('<p>Bonjour,<br/><br/>
  42.                 Vos identifiants de connexion à la <a href="https://app.lfpl.fr/lfpldeclaration/public/">plateforme de déclaration de frais de déplacement</a> sont les suivants :<br/>
  43.                     Identifiant : '.$user->getEmail().'<br/>
  44.                     Mot de passe : '.$password.'<br/>
  45.                 <br/>Sportivement,<br/>
  46.                 <img src="cid:signature"/><br/>
  47.                 Mail: <a href="mailto:comptabilite@lfpl.fff.fr">comptabilite@lfpl.fff.fr</a></p>
  48.                 
  49.                 <p><span style="color: #d8171c">Ce mail a été généré automatiquement, merci de ne pas répondre.</span></p>');
  50.         
  51.                 $mailer->send($email);
  52.             }
  53.             return $this->redirectToRoute('check_mail');
  54.         }
  55.         
  56.         return $this->render('mdp/resetpassword.html.twig', [
  57.             'motDePasseOublieForm' => $motDePasseOublieForm->createView(),
  58.         ]);
  59.     }
  60.     /**
  61.      * @Route("/check-mail", name="check_mail")
  62.      */
  63.     public function checkmail()
  64.     {
  65.         return $this->render('mdp/checkmail.html.twig');
  66.     }
  67. }