src/Controller/SecurityController.php line 277

Open in your IDE?
  1. <?php
  2. // src/Controller/SecurityController.php
  3. namespace App\Controller;
  4. use App\Entity\Fonctions;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use App\Entity\User;
  10. use App\Entity\Sejour;
  11. use App\Service\EmailsCmdService;
  12. use App\Service\UserService;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  16. class SecurityController extends AbstractController
  17. {
  18.     private $em;
  19.     private $userService;
  20.     private $emailsCmdService;
  21.     public function __construct(EntityManagerInterface $emUserService $userServiceEmailsCmdService $emailsCmdService)
  22.     {
  23.         $this->em $em;
  24.         $this->userService $userService;
  25.         $this->emailsCmdService $emailsCmdService;
  26.     }
  27.     /**
  28.      * @Route("/LoginAdmin", name="app_login")
  29.      */
  30.     public function login(AuthenticationUtils $authenticationUtils): Response
  31.     {
  32.         // get the login error if there is one
  33.         $error $authenticationUtils->getLastAuthenticationError();
  34.         // last username entered by the user
  35.         $lastUsername $authenticationUtils->getLastUsername();
  36.         return $this->render('security/login.html.twig', [
  37.             'last_username' => $lastUsername,
  38.             'error' => $error
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route("/logout", name="app_logout")
  43.      */
  44.     public function logout()
  45.     {
  46.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  47.     }
  48.     /**
  49.      * @Route("/Parent/logout", name="app_logout_parent")
  50.      */
  51.     public function logoutParent()
  52.     {
  53.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  54.     }
  55.     /**
  56.      * @Route("/Accompagnateur/logout", name="app_logout_Accompagnateur")
  57.      */
  58.     public function logoutAcompa()
  59.     {
  60.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  61.     }
  62.     /**
  63.      * @Route("/Partenaire/logout", name="app_logout_Partenaire")
  64.      */
  65.     public function logoutPartenaire()
  66.     {
  67.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
  68.     }
  69.     /**
  70.      * @Route("/Accompagnateur/login", name="app_back_Acommpa")
  71.      */
  72.     public function Acommpalogin(AuthenticationUtils $authenticationUtils): Response
  73.     {
  74.         if ($this->getUser()) {
  75.             $this->redirectToRoute('layoutAccueil');
  76.         }
  77.         // get the login error if there is one
  78.         $error $authenticationUtils->getLastAuthenticationError();
  79.         // last username entered by the user
  80.         $lastUsername $authenticationUtils->getLastUsername();
  81.         $listeFonctions $this->em->getRepository(Fonctions::class)->findBy(array('statut' => 2));
  82.         return $this->render('Accompagnateur/LoginAccompagnateur.html.twig', ['listeFonctions' => $listeFonctions'last_username' => $lastUsername'error' => $error]);
  83.     }
  84.     /**
  85.      * @Route("/ForgotPass",name="forgotPass")
  86.      */
  87.     function forgot_Password()
  88.     {
  89.         return $this->render('security/DemandePassword.html.twig');
  90.     }
  91.     /**
  92.      * @Route("/forgotPassparent",name="forgotPassparent")
  93.      */
  94.     function forgot_Password2()
  95.     {
  96.         return $this->render('security/DemandePasswordParent.html.twig');
  97.     }
  98.     /**
  99.      * @Route("/Accompagnateur/NewPassword",name="New_Password")
  100.      */
  101.     function Create_New_Password(Request $request)
  102.     {
  103.         $password $request->get('password');
  104.         $userId $request->get('userID');
  105.         $USerService $this->userService;
  106.         $user $this->getDoctrine()
  107.             ->getRepository(User::class)->find($userId);
  108.         $USerService->updatPassw($user$password);
  109.         return new response("done");
  110.     }
  111.     /**
  112.      * @Route("/changerPassword",name="changer_Password")
  113.      */
  114.     function changerPassword(Request $request)
  115.     {
  116.         $password $request->get('password');
  117.         $userId $request->get('userID');
  118.         $USerService $this->userService;
  119.         $USerService->updatPassw($userId$password);
  120.         return new response("done");
  121.     }
  122.     /**
  123.      * @Route("/Accompagnateur/request_password",name="request_password")
  124.      */
  125.     function request_password(Request $request)
  126.     {
  127.         $code $request->get('code');
  128.         $sejour $this->em->getRepository(Sejour::class)->findOneBy(['codeSejour' => $code]);
  129.         $user null;
  130.         if ($sejour != null) {
  131.             $user $sejour->getIdAcommp();
  132.         }
  133.         if ($user == null) {
  134.             return $this->render('security/UsernotFound.html.twig');
  135.         } else {
  136.             $encript hash("sha256"$user->getUsername() . $user->getId());
  137.             $url_newPass $this->get('router')->generate('directloginOM_token', array("token" => str_replace("."" "$user->getEmail()), 'userHash' => $encript), UrlGeneratorInterface::ABSOLUTE_URL);
  138.             $USerService $this->userService;
  139.             $USerService->sendPasswordMail($user->getEmail(), $url_newPass);
  140.             // dd($USerService->sendPasswordMail($user->getEmail(),$url_newPass));
  141.             //dd($user->getEmail().' '.$url_newPass);
  142.             return $this->render('security/DemandePasswordValide.html.twig');
  143.         }
  144.     }
  145.     /**
  146.      * @Route("/Parent/request_password_Parent",name="request_passwordParent")
  147.      */
  148.     function request_password_parent(Request $request)
  149.     {
  150.         $mail $request->get('code');
  151.         $user $this->em->getRepository(User::class)->findOneBy(['email' => $mail]);
  152.         if ($user == null) {
  153.             return $this->render('security/UsernotFound.html.twig');
  154.         } else {
  155.             $encript hash("sha256"$user->getUsername() . $user->getId());
  156.             $url_newPass $this->get('router')->generate('directloginOM_tokenv2', array("token" => str_replace("."" "$user->getEmail()), 'userHash' => $encript), UrlGeneratorInterface::ABSOLUTE_URL);
  157.             $USerService $this->userService;
  158.             $USerService->sendPasswordMail($user->getEmail(), $url_newPass);
  159.             // dd($USerService->sendPasswordMail($user->getEmail(),$url_newPass));
  160.             //dd($user->getEmail().' '.$url_newPass);
  161.             return $this->render('security/DemandePasswordValide.html.twig');
  162.         }
  163.     }
  164.     /**
  165.      * @Route("/Partenaire/request_password_Partenaire",name="request_password_parentenaire")
  166.      */
  167.     function request_password_parentenaire(Request $request)
  168.     {
  169.         ini_set("max_execution_time", -1);
  170.         ini_set('memory_limit''-1');
  171.         $mail $request->get('code');
  172.         $user $this->em->getRepository(User::class)->findOneBy(['email' => $mail]);
  173.         if ($user == null) {
  174.             return $this->render('security/UsernotFound.html.twig');
  175.         } else {
  176.             $encript hash("sha256"$user->getUsername() . $user->getId());
  177.             $url_newPass $this->get('router')->generate('directloginOM_tokenv3', array("token" => str_replace("."" "$user->getEmail()), 'userHash' => $encript), UrlGeneratorInterface::ABSOLUTE_URL);
  178.             $USerService $this->userService;
  179.             $USerService->sendPasswordMail($user->getEmail(), $url_newPass);
  180.             // dd($USerService->sendPasswordMail($user->getEmail(),$url_newPass));
  181.             //dd($user->getEmail().' '.$url_newPass);
  182.             return $this->render('security/DemandePasswordValide.html.twig');
  183.         }
  184.     }
  185.     /**
  186.      * @Route("/directloginOM_tokenv2/{token}/{userHash}",name="directloginOM_tokenv2")
  187.      */
  188.     function directloginOM_tokenv2($token$userHash)
  189.     {
  190.         $token str_replace(" ""."$token);
  191.         $user $this->getDoctrine()
  192.             ->getRepository(User::class)->findOneBy(array('email' => $token));
  193.         if ((hash("sha256"$user->getUsername() . $user->getId()) == $userHash)) {
  194.             return $this->render('security/DemandePasswordParentv.html.twig', ["userToSetPassword" => $user]);
  195.         } else {
  196.             return $this->redirectToRoute("app_back_Parent");
  197.         }
  198.     }
  199.     /**
  200.      * @Route("/directloginOM_token/{token}/{userHash}",name="directloginOM_token")
  201.      */
  202.     function directloginOM($token$userHash)
  203.     {
  204.         $token str_replace(" ""."$token);
  205.         $user $this->getDoctrine()
  206.             ->getRepository(User::class)->findOneBy(array('email' => $token));
  207.         if ((hash("sha256"$user->getUsername() . $user->getId()) == $userHash)) {
  208.             return $this->render('security/NewPassword.html.twig', ["userToSetPassword" => $user]);
  209.         } else {
  210.             return $this->redirectToRoute("app_back_Acommpa");
  211.         }
  212.     }
  213.     /**
  214.      * @Route("/Parent/login", name="app_back_Parent")
  215.      */
  216.     public function Parentlogin(AuthenticationUtils $authenticationUtils): Response
  217.     {
  218.         if ($this->getUser()) {
  219.             $this->redirectToRoute('layoutAccueil');
  220.         }
  221.         // get the login error if there is one
  222.         $error $authenticationUtils->getLastAuthenticationError();
  223.         // last username entered by the user
  224.         $lastUsername $authenticationUtils->getLastUsername();
  225.         //name of twing of loging
  226.         return $this->render('Parent/LoginParent.html.twig', ['last_username' => $lastUsername'error' => $error]);
  227.     }
  228.     /**
  229.      * @Route("/Partenaire/login", name="app_login_back_Partenaire")
  230.      */
  231.     public function loginpartenair(AuthenticationUtils $authenticationUtils): Response
  232.     {
  233.         // get the login error if there is one
  234.         $error $authenticationUtils->getLastAuthenticationError();
  235.         // last username entered by the user
  236.         $lastUsername $authenticationUtils->getLastUsername();
  237.         return $this->render('partenaire/authentification.html.twig', [
  238.             'last_username' => $lastUsername,
  239.             'error' => $error
  240.         ]);
  241.     }
  242.     /**
  243.      * @Route("/directloginOM_tokenv3/{token}/{userHash}",name="directloginOM_tokenv3")
  244.      */
  245.     function directloginOM_tokenv3($token$userHash)
  246.     {
  247.         $token str_replace(" ""."$token);
  248.         $user $this->getDoctrine()
  249.             ->getRepository(User::class)->findOneBy(array('email' => $token));
  250.         //               dd($user);
  251.         if ((hash("sha256"$user->getUsername() . $user->getId()) == $userHash)) {
  252.             return $this->render('security/DemandePasswordvpartenaire.html.twig', ["userToSetPassword" => $user]);
  253.         } else {
  254.             return $this->redirectToRoute("app_login_back_Partenaire");
  255.         }
  256.     }
  257.     /**
  258.      * @Route("/forgotPasspatenaire",name="patenaireforget")
  259.      */
  260.     function forgot_Password3()
  261.     {
  262.         return $this->render('security/DemandePasswordPartenaire.html.twig');
  263.     }
  264.     #[Route('/Parent/login_check'name'login_check')]
  265.     public function check(): never
  266.     {
  267.         throw new \LogicException('This code should never be reached');
  268.     }
  269.     
  270. /*     public function mailTesterAction(Request $request)
  271.     {
  272.         
  273.         $user = $this->getUser();
  274.         $sendTo = 'test@gmail.com';
  275.         $loginUrl = $this->emailsCmdService->requestLoginLink($user);
  276.         $extra = [
  277.             "identifiant" => $sendTo,
  278.             "senduser" => $user,
  279.             "roles" => $user->getRoles(),
  280.             "nom" => $user->getNom(),
  281.             "prenom" => $user->getPrenom(),
  282.             "loginLink" => $loginUrl
  283.         ];
  284.         $this->emailsCmdService->sendMail(
  285.             $sendTo, 
  286.             'Immortalisez les souvenirs inoubliables du séjour de votre enfant !', 
  287.             'Album_Sej_Notif',
  288.             $extra
  289.         );
  290.     } */
  291. }