src/Controller/SecurityController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Service\Notifications;
  5. use Doctrine\ORM\EntityManager;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  7. use Symfony\Bridge\Doctrine\ManagerRegistry;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  14. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  15. use Twig\Environment;
  16. class SecurityController extends AbstractController
  17. {
  18.     /**
  19.      * @Route("/login", name="app_login")
  20.      */
  21.     public function login(Request $requestAuthenticationUtils $authenticationUtils): Response
  22.     {
  23.         // get the login error iff there is one
  24.         $error $authenticationUtils->getLastAuthenticationError();
  25.         // last username entered by the user
  26.         $lastUsername $authenticationUtils->getLastUsername();
  27.         return $this->render('security/index.html.twig',
  28.             ['last_username' => $lastUsername'error' => $error]);
  29.     }
  30.     /**
  31.      * @Route("/logout", name="app_logout", methods={"GET"})
  32.      */
  33.     public function logout()
  34.     {
  35.         // throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  36.     }
  37.     /**
  38.      * @Route("public/restore/password", name="app_restore_password")
  39.      */
  40.     public function restore(  Request $request,  Environment $twigNotifications $notifUserPasswordEncoderInterface $passwordEncoder  ) {
  41.         $em $this->getDoctrine()->getManager();
  42.         $email $request->get('email');
  43.         $userD $em->getRepository(User::class)->findOneBy(['email' => $email]);
  44.         if ( ! empty($userD)) {
  45.             $passNew rand(1000099999999);
  46.             $this->changePass($userD->getId(), $passNew$passwordEncoder);
  47.             $this->addFlash(
  48.                 'success',
  49.                 'Te enviamos un correo con tu nueva contraseña.'
  50.             );
  51.             $subject 'Nueva Contraseña';
  52.             $message "Estimado Usuario, agradecemos que seas parte de Piensa Pro y para seguir conectados, te hemos restablecido tu contraseña para el acceso a nuestra plataforma. <br> <br>
  53.      
  54.             Tu nueva contraseña es: <strong>" $passNew " </strong> <br><br>
  55.  
  56.   Dentro del sistema podrás visualizar el proceso de avance en tus cursos. Solo debes ingresar con tu correo y la nueva contraseña. <br><br> ¡Te esperamos! <br>  Saludos Cordiales";
  57.             $htmlContents $twig->render('security/email.html.twig', [
  58.                 'title'    => $subject,
  59.                 'messages' => $message,
  60.             ]);
  61.             $notif->newNotificationSystem(
  62.                 $email,
  63.                 $subject,
  64.                 $htmlContents
  65.             );
  66.         } else {
  67.             $this->addFlash(
  68.                 'error',
  69.                 'El correo ingresado no esta disponible en la plataforma'
  70.             );
  71.         }
  72.         return $this->redirectToRoute('app_login');
  73.     }
  74.     function changePass($id$pass$passwordEncoder)
  75.     {
  76.         $em $this->getDoctrine()->getManager();
  77.         $userD $em->getRepository(User::class)->find($id);
  78.         $userD->setPassword($passwordEncoder->encodePassword(
  79.             $userD,
  80.             $pass
  81.         ));
  82.         $em->flush();
  83.         return true;
  84.     }
  85.     /**
  86.      * @Route("public/email", name="dash_email" )
  87.      *
  88.      */
  89.     public function emails(Environment $twig): Response
  90.     {
  91.         $em $this->getDoctrine()->getManager();
  92.         $subject 'Bienvenido';
  93.         $passNew rand(1000099999);
  94.         $subject 'Nueva Contraseña';
  95.         $message "Estimado Beneficiario   <br><br> Agradecemos que seas parte de la red de asistencia digital FORTALECE Pyme  Ñuble y para seguir vinculados, 
  96. te hemos generado un acceso a nuestra plataforma interna.<br> <br>
  97. Dentro de esta plataforma podrás:
  98. <ul>
  99.    <li>Visualizar el proceso de avance en tu Transformación Digital, mediante el acceso a tus Informes de diagnóstico y asistencia técnica.</li> <br>
  100.    <li>Ver noticias de nuestra red y otra información relevante, como capacitaciones y charlas, entre otros.</li> <br>
  101.       <li>Un registro de las capacitaciones que has realizado con nosotros.</li> <br>
  102. </ul> 
  103. <br>
  104. Solo debes ingresar con tu correo y los 4 primeros dígitos de tu RUT. <br><br>
  105. ¡Te esperamos! <br>
  106. Saludos Cordiales";
  107.         $htmlContents $twig->render('security/email.html.twig', [
  108.             'title'    => $subject,
  109.             'messages' => $message,
  110.         ]);
  111.         print_r($htmlContents);
  112.         exit;
  113.     }
  114. }