src/Controller/SecurityController.php line 75

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  10. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use App\Entity\BFUser;
  13. use App\Entity\BFChallenge;
  14. use App\Entity\BFChallengeEdition;
  15. use App\Entity\BFFestival;
  16. use App\Entity\BFEdition;
  17. use App\Entity\BFPaymentIntentEdition;
  18. use App\Entity\BFPaymentIntentAdmin;
  19. use App\Entity\BFResetPassword;
  20. use App\Entity\BFAdminLicences;
  21. use App\Form\Type\BFUserType;
  22. use App\Form\Type\ResetPassword1Type;
  23. use App\Form\Type\ResetPassword2Type;
  24. use App\Form\Type\BFPaymentIntentAdminType;
  25. use App\Utilities\Secure;
  26. use Symfony\Component\Form\FormError;
  27. use App\Utilities\Mail;
  28. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  29. use App\Form\Type\BFAdminLicenceType;
  30. use App\Form\Type\FindPaymentByStripeIdType;
  31. use App\Object\Statistic;
  32. use Stripe\Stripe;
  33. use Stripe\StripeClient;
  34. use Stripe\PaymentIntent;
  35. use Stripe\PaymentMethod;
  36. use Stripe\Event;
  37. class SecurityController extends AbstractController
  38. {
  39.     /**
  40.      * @Route("/security/login", name="app_login")
  41.      */
  42.     public function login(AuthenticationUtils $authenticationUtils): Response
  43.     {
  44.         // if ($this->getUser()) {
  45.         //     return $this->redirectToRoute('target_path');
  46.         // }
  47.         // get the login error if there is one
  48.         $error $authenticationUtils->getLastAuthenticationError();
  49.         // last username entered by the user
  50.         $lastUsername $authenticationUtils->getLastUsername();
  51.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  52.     }
  53.     
  54.     /**
  55.      * @Route("/security/logout", name="app_logout")
  56.      */
  57.     public function logout()
  58.     {
  59.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  60.     }
  61.     
  62.     /**
  63.     * @Route("/security/resetpassword" , name="app_resetpassword")
  64.     */
  65.     public function ResetPassword(Request $request)
  66.     {
  67.         $formreset $this->createForm(ResetPassword1Type::class);
  68.         
  69.         $formreset->handleRequest($request);
  70.         if($formreset->isSubmitted() && $formreset->isValid()){
  71.             $email=$formreset->getData()['email'];
  72.             
  73.             //get the user
  74.             $user=$this->getDoctrine()->getRepository(BFUser::class)->findOneBy(array('email'=>$email));
  75.             
  76.             if($user==null)
  77.             {
  78.                 $formreset->get('email')->addError(new FormError('Email inconnu'));
  79.             }
  80.             else
  81.             {
  82.                 $this->ClearUserResetPassword($user);
  83.                 
  84.                 $datetime = new \DateTime();
  85.                 $datetime->add(new \DateInterval("P1D")); //add 1day
  86.                 
  87.                 $bfresetpassword = new BFResetPassword();
  88.                 $bfresetpassword->setUser($user);
  89.                 $bfresetpassword->setToken($this->GetUniqueToken());
  90.                 $bfresetpassword->setValiditydate($datetime);
  91.                 
  92.                 $entityManager $this->getDoctrine()->getManager();
  93.                 $entityManager->persist($bfresetpassword);
  94.                 $entityManager->flush($bfresetpassword);
  95.                 
  96.                 //Send mail
  97.                 
  98.                 $link $this->generateUrl('app_resetpassword_token', ['token'=>$bfresetpassword->getToken()], UrlGeneratorInterface::ABSOLUTE_URL);
  99.                                
  100.                 $txtmessage "Pour reinitialier votre mot de passe rendez vous sur: ".$link;
  101.                 $subject "Reinitialiser le mot de passe";
  102.                 
  103.                 $htmlmessage $this->render('mail/resetpasswordmail.html.twig', [
  104.                     'subject' => $subject,
  105.                     'link' => $link,
  106.                 ]);
  107.                 
  108.                 
  109.                 $return Mail::SendMailToMail($email$subject$htmlmessage$txtmessage);
  110.                 
  111.                 if($return ==false)
  112.                 {
  113.                     $this->addFlash('danger''Erreur lors de l\'envoi du mail');
  114.                 }
  115.                 
  116.                 return $this->render('security/resetpasswordconfirmation.html.twig', [
  117.                     'passwordchanged' => false,
  118.                 ]);
  119.             }
  120.         }
  121.         if($formreset->isSubmitted() && !$formreset->isValid())
  122.         {
  123.             foreach($formreset->getErrors(true) as $error)
  124.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  125.             return $this->redirect($request->getUri());
  126.         }
  127.         
  128.         return $this->render('security/resetpassword.html.twig', [
  129.             'formreset' => $formreset->createView(),
  130.         ]);
  131.     }
  132.     
  133.     /**
  134.     * @Route("/security/resetpassword/{token}", name="app_resetpassword_token")
  135.     */
  136.     public function ResetPasswordWithToken($tokenRequest $requestUserPasswordEncoderInterface $passwordEncoder)
  137.     {
  138.         $bfresetpassword $this->getDoctrine()->getRepository(BFResetPassword::class)->findOneBy(array('token'=>$token));
  139.         $entityManager $this->getDoctrine()->getManager();
  140.         
  141.         if($bfresetpassword->getValiditydate()< new \DateTime())
  142.         {
  143.             $entityManager->remove($bfresetpassword);
  144.             $entityManager->flush();
  145.             $bfresetpassword=null;
  146.         }
  147.         
  148.         if($bfresetpassword==null)
  149.         {
  150.             return $this->redirectToRoute("app_resetpassword");
  151.         }
  152.         
  153.         $formreset $this->createForm(ResetPassword2Type::class);
  154.         
  155.         $formreset->handleRequest($request);
  156.         if($formreset->isSubmitted() && $formreset->isValid()){
  157.             $email=$formreset->getData()['email'];
  158.             $user=$bfresetpassword->getUser();
  159.             
  160.             //check email with bfresetpassworduser email
  161.             if($email != $bfresetpassword->getUser()->getEmail())
  162.             {
  163.                 $formreset->get('email')->addError(new FormError('Email inconnu'));
  164.             }
  165.             else
  166.             {
  167.                 $password $passwordEncoder->encodePassword($user$formreset->getData()['plainPassword']);
  168.                 $user->setPassword($password);
  169.                 // 4) save the User!
  170.                 $entityManager $this->getDoctrine()->getManager();
  171.                 $entityManager->persist($user);
  172.                 $entityManager->flush();
  173.                 
  174.                 //remove the resetpasswordrequest
  175.                 $entityManager->remove($bfresetpassword);
  176.                 $entityManager->flush();
  177.                 
  178.                 return $this->render('security/resetpasswordconfirmation.html.twig', [
  179.                     'passwordchanged' => true,
  180.                 ]);
  181.             }
  182.         }
  183.         if($formreset->isSubmitted() && !$formreset->isValid())
  184.         {
  185.             foreach($formreset->getErrors(true) as $error)
  186.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  187.             return $this->redirect($request->getUri());
  188.         }
  189.         
  190.         return $this->render('security/resetpassword.html.twig', [
  191.             'formreset' => $formreset->createView(),
  192.         ]);
  193.     }
  194.     
  195.     /**
  196.     * @Route ("/security/account/superadmin/setdefault", name="app_superadmin_setdefault")
  197.     */
  198.     public function SetDefaultSuperAdmin(Request $request)
  199.     {
  200.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  201.         
  202.         //Check if there is an role_super_admin in the database
  203.         $userrepository =$this->getDoctrine()->getRepository(BFUser::class);
  204.         $superadmins $userrepository->findByRole('ROLE_SUPER_ADMIN');
  205.         
  206.         if(count($superadmins)<=1)
  207.         {
  208.             //set the first user
  209.             $firstuser $userrepository->findFirst();
  210.             
  211.             $firstuser->setRoles(array('ROLE_SUPER_ADMIN'));
  212.             
  213.             $entityManager $this->getDoctrine()->getManager();
  214.             $entityManager->persist($firstuser);
  215.             $entityManager->flush();
  216.             
  217.             $this->addFlash('primary''Super admin role add default');
  218.         }
  219.         
  220.         return $this->redirectToRoute('home_route',[
  221.             'routename' => 'account',
  222.         ]);   
  223.                 
  224.     }
  225.     
  226.     /**
  227.     * @Route ("/security/account/superadmin/add/{email}", name="app_superadmin_add")
  228.     */
  229.     public function AddSuperAdmin($emailRequest $request)
  230.     {
  231.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  232.         
  233.         //Check if there is an role_super_admin in the database
  234.         $user =$this->getDoctrine()->getRepository(BFUser::class)->findOneBy(['email'=>$email]);
  235.         
  236.         if($user!=null)
  237.         {
  238.             //set the first user
  239.             
  240.             $user->setRoles(array('ROLE_SUPER_ADMIN'));
  241.             
  242.             $entityManager $this->getDoctrine()->getManager();
  243.             $entityManager->persist($user);
  244.             $entityManager->flush();
  245.             
  246.             $this->addFlash('primary''Super admin role add');
  247.         }
  248.         
  249.         return $this->redirectToRoute('home_route',[
  250.                 'routename' => 'account',
  251.             ]);      
  252.                 
  253.     }
  254.     
  255.     /**
  256.     * @Route ("/security/account/superadmin/remove/{email}", name="app_superadmin_remove")
  257.     */
  258.     public function RemoveSuperAdmin($emailRequest $request)
  259.     {
  260.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  261.         
  262.         //Check if there is an role_super_admin in the database
  263.         $user =$this->getDoctrine()->getRepository(BFUser::class)->findOneBy(['email'=>$email]);
  264.         
  265.         if($user!=null)
  266.         {
  267.             //set the first user
  268.             
  269.             $user->setRoles(array(''));
  270.             
  271.             $entityManager $this->getDoctrine()->getManager();
  272.             $entityManager->persist($user);
  273.             $entityManager->flush();
  274.             
  275.             $this->addFlash('primary''Super admin role remove');
  276.         }
  277.         
  278.         return $this->redirectToRoute('home_route',[
  279.                 'routename' => 'account',
  280.         ]);
  281.     }
  282.     
  283.     /**
  284.     * @Route ("/admin/superadmin", name="admin_superadmin_view")
  285.     */
  286.     public function ShowSuperAdminView(Request $request)
  287.     {
  288.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  289.         
  290.         $user $this->getUser();
  291.         
  292.         $adminlicences=new BFAdminLicences();
  293.         
  294.         //form add option or offer
  295.         $formaddoption=$this->createForm(BFAdminLicenceType::class, $adminlicences);
  296.         $formaddoption->handleRequest($request);
  297.         if($formaddoption->isSubmitted() && $formaddoption->isValid())
  298.         {
  299.             $adminlicences=$formaddoption->getData();
  300.             
  301.             $em $this->getDoctrine()->getManager();
  302.             $em->persist($adminlicences);
  303.             $em->flush()    ;
  304.             
  305.             $this->addFlash('primary''L\'option a été ajoutée');
  306.                 
  307.             return $this->redirect($request->getUri());
  308.             
  309.         }
  310.         if($formaddoption->isSubmitted() && !$formaddoption->isValid())
  311.         {
  312.             foreach($formaddoption->getErrors(true) as $error)
  313.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  314.             return $this->redirect($request->getUri());
  315.         }
  316.         
  317.         //form find payment by stripeid
  318.         $formfindpayment $this->createForm(FindPaymentByStripeIdType::class);
  319.         $formfindpayment->handleRequest($request);
  320.         if($formfindpayment->isSubmitted() && $formfindpayment->isValid())
  321.         {
  322.             $stripeid=$formfindpayment['stripeid']->getData();
  323.             
  324.             $paymentintent=$this->getDoctrine()->getRepository(BFPaymentIntentEdition::class)->findOneBy(['stripeid' => $stripeid]);
  325.             
  326.             if($paymentintent!=null)
  327.             {
  328.                 return $this->redirectToRoute('payment_admin_details',[
  329.                 'idpayment' => $paymentintent->getId(),
  330.                 ]);
  331.             }
  332.             else
  333.             {
  334.                 $this->addFlash('danger''None payment found');
  335.                 return $this->redirect($request->getUri());
  336.             }        
  337.         }
  338.         if($formaddoption->isSubmitted() && !$formaddoption->isValid())
  339.         {
  340.             foreach($formaddoption->getErrors(true) as $error)
  341.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  342.             return $this->redirect($request->getUri());
  343.         }
  344.         
  345.         //admin payments
  346.         $adminpayments $this->getDoctrine()->getRepository(BFPaymentIntentAdmin::class)->findAll();
  347.         
  348.         //admin licences list
  349.         $adminlicences $this->getDoctrine()->getRepository(BFAdminLicences::class)->findAllValid();
  350.         
  351.         //admin statistics
  352.         $statistics = array();
  353.         
  354.         $userstat = new Statistic();
  355.         $userstotal $this->getDoctrine()->getRepository(BFUser::class)->findAll();
  356.         $userlastmonth $this->getDoctrine()->getRepository(BFUser::class)->findAllLastMonth();
  357.         $userstat->setName('User');
  358.         $userstat->setLastmonth(count($userlastmonth));
  359.         $userstat->setTotal(count($userstotal));
  360.         array_push($statistics,$userstat);
  361.         
  362.         $festivalstat= new Statistic();
  363.         $festivaltotal $this->getDoctrine()->getRepository(BFFestival::class)->findAll();
  364.         $festivallastmonth $this->getDoctrine()->getRepository(BFFestival::class)->findAllLastMonth();
  365.         $festivalstat->setName('Festival');
  366.         $festivalstat->setLastmonth(count($festivallastmonth));
  367.         $festivalstat->setTotal(count($festivaltotal));
  368.         array_push($statistics,$festivalstat);
  369.         
  370.         $challengestat= new Statistic();
  371.         $challengetotal $this->getDoctrine()->getRepository(BFChallenge::class)->findAll();
  372.         $challengelastmonth $this->getDoctrine()->getRepository(BFChallenge::class)->findAllLastMonth();
  373.         $challengestat->setName('Challenge');
  374.         $challengestat->setLastmonth(count($challengelastmonth));
  375.         $challengestat->setTotal(count($challengetotal));
  376.         array_push($statistics,$challengestat);
  377.         
  378.         $stateditions = new Statistic();
  379.         $activeeditions $this->getDoctrine()->getRepository(BFEdition::class)->findBy(['isactive'=>true]);
  380.         $stateditions->setName('Editions actives');
  381.         $stateditions->setTotal(count($activeeditions));
  382.         array_push($statistics$stateditions);
  383.         
  384.          
  385.         $stateditionschallenge = new Statistic();
  386.         $activeeditionschallenge $this->getDoctrine()->getRepository(BFChallengeEdition::class)->findBy(['isactive'=>true]);
  387.         $stateditionschallenge->setName('Editions Challenge actives');
  388.         $stateditionschallenge->setTotal(count($activeeditionschallenge));
  389.         array_push($statistics$stateditionschallenge);
  390.         
  391.         return $this->render('adminsuperadmin.html.twig', [
  392.             'userdescription' => $user->getDescription(),
  393.             'formaddoption' => $formaddoption->createView(),
  394.             'formfindpayment' => $formfindpayment->createView(),
  395.             'bfadminlicences' => $adminlicences,
  396.             'statistics' => $statistics,
  397.             'bfpaymentintentadmins' => $adminpayments,
  398.             'activesuperadmin' => 1,
  399.         ]);
  400.                         
  401.     }
  402.     /**
  403.      * @Route ("/admin/superadmin/all", name="admin_superadmin_all")
  404.      */
  405.     public function ShowSuperAdminAllView(SessionInterface $sessionPaginatorInterface $paginatorRequest $request)
  406.     {
  407.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  408.         $user $this->getUser();
  409.         $festivals $this->getDoctrine()->getRepository(BFFestival::class)->findAll();
  410.         $challenges $this->getDoctrine()->getRepository(BFChallenge::class)->findAll();
  411.         $session->set('allfestivals'$festivals);
  412.         $session->set('allchallenges'$challenges);
  413.         $paginationfestivals $paginator->paginate(
  414.             $session->get('allfestivals'), /* query NOT result */
  415.             $request->query->getInt('page'1), /*page number*/
  416.             10 /*limit per page*/
  417.         );
  418.         $paginationchallenges $paginator->paginate(
  419.             $session->get('allchallenges'), /* query NOT result */
  420.             $request->query->getInt('page'1), /*page number*/
  421.             10 /*limit per page*/
  422.         );
  423.         return $this->render('adminsuperadminall.html.twig', [
  424.             'userdescription' => $user->getDescription(),
  425.             'paginationfestivals' => $paginationfestivals,
  426.             'paginationchallenges' => $paginationchallenges,
  427.             'activesuperadmin' => 2,
  428.         ]);
  429.     }
  430.     /**
  431.     * @Route("/admin/superadmin/paymentadmin/create", name="admin_superadmin_paymentadmin_create")
  432.     */
  433.     public function CreatePaymentIntentAdmin(Request $request)
  434.     {
  435.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  436.         
  437.         $user $this->getUser();
  438.         
  439.         $bfpaymentintentbfadmin = new BFPaymentIntentAdmin();
  440.         
  441.         //form add option or offer
  442.         $formbfpaymentintentbfadmin=$this->createForm(BFPaymentIntentAdminType::class, $bfpaymentintentbfadmin, ['submit_label'=>'Créer']);
  443.         $formbfpaymentintentbfadmin->handleRequest($request);
  444.         if($formbfpaymentintentbfadmin->isSubmitted() && $formbfpaymentintentbfadmin->isValid())
  445.         {
  446.             $bfpaymentintentbfadmin=$formbfpaymentintentbfadmin->getData();
  447.             
  448.             $em $this->getDoctrine()->getManager();
  449.             $em->persist($bfpaymentintentbfadmin);
  450.             $em->flush()    ;
  451.             
  452.             $this->addFlash('primary''Le paiement admin a été créé');
  453.                 
  454.             return $this->redirectToRoute('admin_superadmin_paymentadmin_edit', ['idpaymentintentadmin' => $bfpaymentintentbfadmin->getId() ]);
  455.             
  456.         }
  457.         if($formbfpaymentintentbfadmin->isSubmitted() && !$formbfpaymentintentbfadmin->isValid())
  458.         {
  459.             foreach($formbfpaymentintentbfadmin->getErrors(true) as $error)
  460.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  461.             return $this->redirect($request->getUri());
  462.         }
  463.         
  464.         return $this->render('payments/superadminpaymentadmin.html.twig', [
  465.             'userdescription' => $user->getDescription(),
  466.             'formbfpaymentintentbfadmin' => $formbfpaymentintentbfadmin->createView(),
  467.             'activesuperadmin' => 1,
  468.         ]);
  469.     }
  470.     
  471.     /**
  472.     * @Route("/admin/superadmin/paymentadmin/edit/{idpaymentintentadmin}", name="admin_superadmin_paymentadmin_edit")
  473.     */
  474.     public function EditPaymentIntentAdmin(int $idpaymentintentadminRequest $request)
  475.     {
  476.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  477.         
  478.         $user $this->getUser();
  479.         
  480.         $bfpaymentintentbfadmin $this->getDoctrine()->getRepository(BFPaymentIntentAdmin::class)->find($idpaymentintentadmin);
  481.         
  482.         if($bfpaymentintentbfadmin==null)
  483.             throw $this->createNotFoundException();
  484.         
  485.         //form add option or offer
  486.         $formbfpaymentintentbfadmin=$this->createForm(BFPaymentIntentAdminType::class, $bfpaymentintentbfadmin);
  487.         $formbfpaymentintentbfadmin->handleRequest($request);
  488.         if($formbfpaymentintentbfadmin->isSubmitted() && $formbfpaymentintentbfadmin->isValid())
  489.         {
  490.             $bfpaymentintentbfadmin=$formbfpaymentintentbfadmin->getData();
  491.             
  492.             $em $this->getDoctrine()->getManager();
  493.             $em->persist($bfpaymentintentbfadmin);
  494.             $em->flush()    ;
  495.             
  496.             $this->addFlash('primary''Le paiement admin a été édité');
  497.                 
  498.             return $this->redirect($request->getUri());
  499.             
  500.         }
  501.         if($formbfpaymentintentbfadmin->isSubmitted() && !$formbfpaymentintentbfadmin->isValid())
  502.         {
  503.             foreach($formbfpaymentintentbfadmin->getErrors(true) as $error)
  504.                 $this->addFlash('danger'"(".$error->getOrigin()->getName().") ".$error->getMessage());
  505.             return $this->redirect($request->getUri());
  506.         }
  507.         
  508.         return $this->render('payments/superadminpaymentadmin.html.twig', [
  509.             'userdescription' => $user->getDescription(),
  510.             'formbfpaymentintentbfadmin' => $formbfpaymentintentbfadmin->createView(),
  511.             'bfpaymentintentadmin' => $bfpaymentintentbfadmin,
  512.             'activesuperadmin' => 1,
  513.             'isedit' => 1,
  514.         ]);
  515.     }
  516.     
  517.     /**
  518.     * @Route("/admin/superadmin/paymentadmin/delete/{idpaymentintentadmin}", name="admin_superadmin_paymentadmin_delete")
  519.     */
  520.     public function DeletePaymentIntentAdmin(int $idpaymentintentadminRequest $request)
  521.     {
  522.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  523.                 
  524.         $bfpaymentintentbfadmin $this->getDoctrine()->getRepository(BFPaymentIntentAdmin::class)->find($idpaymentintentadmin);
  525.         
  526.         if($bfpaymentintentbfadmin==null)
  527.             throw $this->createNotFoundException();
  528.         
  529.         $em $this->getDoctrine()->getManager();
  530.         $em->remove($bfpaymentintentbfadmin);
  531.         $em->flush()    ;
  532.         $this->addFlash('primary''Le paiement admin a été supprimé');
  533.         return $this->redirectToRoute('admin_superadmin_view');
  534.     }
  535.     
  536.     /**
  537.     * @Route("/admin/superadmin/paymentadmin/send/{idpaymentintentadmin}", name="admin_superadmin_paymentadmin_send")
  538.     */
  539.     public function SendPaymentIntentAdmin(int $idpaymentintentadminRequest $request)
  540.     {
  541.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  542.                 
  543.         $bfpaymentintentbfadmin $this->getDoctrine()->getRepository(BFPaymentIntentAdmin::class)->find($idpaymentintentadmin);
  544.         
  545.         if($bfpaymentintentbfadmin==null)
  546.             throw $this->createNotFoundException();
  547.         
  548.         $subject 'Proposition de procéder au paiement';
  549.         $txtmessage="Pas de message texte disponible, seulement la version html est possible";
  550.         $htmlmessage $this->renderView('mail/adminbfpaymentintentadminmail.html.twig', [
  551.             'subject' => $subject,
  552.             'bfpaymentintentadmin' => $bfpaymentintentbfadmin,
  553.         ]);
  554.         $sent=Mail::SendMailToMail($bfpaymentintentbfadmin->getEmail(), $subject$htmlmessage$txtmessage);
  555.         
  556.         if($sent)
  557.         {
  558.             $this->addFlash('primary''Le paiement admin a été envoyé');
  559.         }
  560.         else
  561.         {
  562.             $this->addFlash('danger''Erreur dans l\'envoie');
  563.         }
  564.         
  565.         return $this->redirectToRoute('admin_superadmin_view');
  566.     }
  567.     
  568.     /**
  569.     * @Route("/paymentadmin/pay/{idpaymentintentadmin}", name="paymentadmin_pay")
  570.     */
  571.     public function ProceedPaymentIntentAdmin(int $idpaymentintentadminRequest $request)
  572.     {
  573.          $bfpaymentintentbfadmin $this->getDoctrine()->getRepository(BFPaymentIntentAdmin::class)->find($idpaymentintentadmin);
  574.         
  575.         if($bfpaymentintentbfadmin==null)
  576.             throw $this->createNotFoundException();
  577.         
  578.         if($bfpaymentintentbfadmin->getSuccessdate()!=null)
  579.             return $this->redirectToRoute('paymentadmin_pay_success',['idpaymentintentadmin'=> $idpaymentintentadmin]);
  580.         
  581.         Stripe::setApiKey($this->getParameter('stripe_secret_key'));
  582.         
  583.         //Create Stripe payment intent and fill data
  584.         $intent PaymentIntent::create([
  585.             'amount'=>$bfpaymentintentbfadmin->getPrice(),
  586.             'currency' => 'eur',
  587.             'description' => $bfpaymentintentbfadmin->getDescription(),
  588.             'receipt_email' => $bfpaymentintentbfadmin->getEmail(),
  589.             'payment_method_types' => ['card'],
  590.             ['metadata' => ['bfpaymentintentadmin_id' => $bfpaymentintentbfadmin->getId()]]
  591.             ]);        
  592.         
  593.         $bfpaymentintentbfadmin->setStripeid($intent->id);
  594.         
  595.         $em $this->getDoctrine()->getManager();
  596.         $em->persist($bfpaymentintentbfadmin);
  597.         $em->flush();
  598.         
  599.         $succesurl $this->generateUrl('paymentadmin_pay_success', [
  600.             'idpaymentintentadmin' => $idpaymentintentadmin,
  601.         ]);
  602.         
  603.         //we can show the payment page
  604.         return $this->render('homepaymentadmin.html.twig',[
  605.             'bfpaymentadmin' => $bfpaymentintentbfadmin,
  606.             'intentsecret' => $intent->client_secret,
  607.             'stripe_public_key' => $this->getParameter('stripe_public_key'),
  608.             'success_url' => $succesurl,
  609.         ]
  610.         );
  611.     }
  612.     
  613.     /**
  614.     * @Route("/paymentadmin/success/{idpaymentintentadmin}", name="paymentadmin_pay_success")
  615.     */
  616.     public function SuccessPaymentIntentAdmin(int $idpaymentintentadminRequest $request)
  617.     {
  618.         $bfpaymentintentbfadmin $this->getDoctrine()->getRepository(BFPaymentIntentAdmin::class)->find($idpaymentintentadmin);
  619.         
  620.         if($bfpaymentintentbfadmin==null)
  621.             throw $this->createNotFoundException();
  622.         
  623.         return $this->render('homepaymentadminsuccess.html.twig');
  624.     }
  625.     
  626.     /**
  627.     * @Route ("/admin/superadmin/adminlicence/delete/{id}", name="admin_superadmin_deletelicence")
  628.     */
  629.     public function DeleteAdminLicence(int $idRequest $request)
  630.     {
  631.         $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
  632.         $bfadminlicence $this->getDoctrine()->getRepository(BFAdminLicences::class)->find($id);
  633.         
  634.         if($bfadminlicence!=null)
  635.         {
  636.             $em $this->getDoctrine()->getManager();
  637.             $em->remove($bfadminlicence);
  638.             $em->flush();
  639.             
  640.             $this->addFlash('primary''L\'option a été supprimée');
  641.             
  642.         }
  643.         else
  644.         {
  645.             $this->addFlash('danger''Erreur durant l\'opération');
  646.         }
  647.          
  648.         return $this->redirectToRoute('admin_superadmin_view');
  649.     }
  650.     
  651.     
  652.     private function ClearUserResetPassword(BFUser $bfuser)
  653.     {
  654.         //get bfreset from user id
  655.         $bfresetpassword $this->getDoctrine()->getRepository(BFResetPassword::class)->findOneBy(['user'=>$bfuser]);
  656.         
  657.         if($bfresetpassword!=null)
  658.         {
  659.             $entityManager $this->getDoctrine()->getManager();
  660.             $entityManager->remove($bfresetpassword);
  661.             $entityManager->flush();
  662.         }
  663.         
  664.     }
  665.     
  666.     private function GetUniqueToken()
  667.     {
  668.         $randomstring="";
  669.         $unique=false;
  670.         
  671.         $resetrepository $this->getDoctrine()->getRepository(BFResetPassword::class);
  672.         
  673.         while(!$unique)
  674.         {
  675.             $randomstring Secure::GenerateKey(20);
  676.             
  677.             $bfresetpassword $resetrepository->findOneBy(array('token'=>$randomstring));
  678.             
  679.             $unique=($bfresetpassword==null);
  680.         }
  681.         
  682.         return $randomstring;
  683.     }
  684.     
  685.     
  686.         
  687. }