src/Controller/Front/AccountController.php line 574

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\EmailNotification\ToAdmin;
  4. use App\Entity\Friend;
  5. use App\Entity\Politician;
  6. use App\Entity\Testament;
  7. use App\Form\SupportPoliticianType;
  8. use App\Form\TestamentType;
  9. use App\Repository\FriendRepository;
  10. use App\Repository\TestamentRepository;
  11. use DateTime;
  12. use Exception;
  13. use function sleep;
  14. use App\Entity\Post;
  15. use App\Entity\User;
  16. use App\Form\PostType;
  17. use DateTimeImmutable;
  18. use App\Entity\Contact;
  19. use App\Form\ContactType;
  20. use App\Entity\Suggestion;
  21. use ColorThief\ColorThief;
  22. use App\Form\ParameterType;
  23. use App\Entity\Notification;
  24. use App\Entity\ResetPassword;
  25. use App\Entity\UserAnonymous;
  26. use App\Entity\ChangePassword;
  27. use App\Entity\InscriptionNote;
  28. use App\Form\ResetPasswordType;
  29. use App\Form\ChangePasswordType;
  30. use App\EmailNotification\ToUser;
  31. use App\Form\InscriptionNoteType;
  32. use App\Repository\PostRepository;
  33. use App\Repository\UserRepository;
  34. use App\Form\CitizenSuggestionType;
  35. use App\Repository\ReportRepository;
  36. use Symfony\Component\Form\FormError;
  37. use Symfony\Component\Mercure\Update;
  38. use Doctrine\ORM\EntityManagerInterface;
  39. use App\Repository\SensibilityRepository;
  40. use App\Repository\UserAnonymousRepository;
  41. use App\Repository\PoliticalPartyRepository;
  42. use App\Repository\PoliticianRepository;
  43. use App\Service\ImageOptimizer;
  44. use Symfony\Component\HttpFoundation\Request;
  45. use Symfony\Component\HttpFoundation\Response;
  46. use Symfony\Component\Routing\Annotation\Route;
  47. use Symfony\Component\HttpFoundation\JsonResponse;
  48. use Symfony\Component\HttpFoundation\Session\Session;
  49. use Symfony\Component\HttpFoundation\File\UploadedFile;
  50. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  51. use Symfony\Component\Messenger\MessageBusInterface;
  52. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  53. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  54. class AccountController extends AbstractController
  55. {
  56.     public function __construct(
  57.         private EntityManagerInterface $manager
  58.     ){}
  59.     public function generateToken(): string
  60.     {
  61.         try {return rtrim(strtr(base64_encode(random_bytes(32)), '+/''-_'), '=');} catch (Exception) {}
  62.     }
  63.     private function generateUniqueName(): string
  64.     {
  65.         return md5(uniqid());
  66.     }
  67.     /* No User type in registration */
  68.     #[Route('/inscription/remarque'name'registration_no_user')]
  69.     public function noUserType(Request $requestEntityManagerInterface $managerSession $session): Response
  70.     {
  71.         $inscriptionNote = new InscriptionNote();
  72.         $form $this->createForm(InscriptionNoteType::class, $inscriptionNote);
  73.         $form->handleRequest($request);
  74.         if ($form->isSubmitted() && $form->isValid()) {
  75.             $inscriptionNote->setEmail($session->get('email') ?? "N/A")
  76.                             ->setFirstname($session->get('firstname') ?? "N/A")
  77.                             ->setLastname($session->get('lastname') ?? "N/A");
  78.             $manager->persist($inscriptionNote);
  79.             $manager->flush();
  80.             $this->addFlash("success""Votre remarque a bien été envoyer, vous recevrez une réponse par mail");
  81.             return $this->redirectToRoute('user_welcome');
  82.         }
  83.         return $this->render('front/registration/no-user-type.html.twig', [
  84.             'form' => $form->createView()
  85.         ]);
  86.     }
  87.     #[Route('/app-user-login'name'user_login')]
  88.     public function index(ReportRepository $reportRepository): Response
  89.     {
  90.         sleep(1);
  91.         /** @var User $user */
  92.         $user $this->getUser();
  93.         $message null;
  94.         $success false;
  95.         if ($user)
  96.         {
  97.             if ($user->getStatus() == "banned")
  98.             {
  99.                 if ($user->getBannedUntil())
  100.                 {
  101.                     $message "Votre compte est suspendu jusqu'au " $user->getBannedUntil()->format('d/m/Y');
  102.                 }
  103.                 else
  104.                 {
  105.                     $message "Votre compte est suspendu";
  106.                 }
  107.                 $report $reportRepository->findOneBy(['user' => $user'status' => 'done'], ['id' => 'DESC']) ?? null;
  108.                 if ($report) { $reason $report->getAnswer(); }
  109.                 $token $user->getToken();
  110.             }
  111.             elseif ($user->getStatus() == "anonymous") {
  112.                 return $this->json([
  113.                    'success' => 'anonymous',
  114.                 ]);
  115.             }
  116.             else
  117.             {
  118.                 $success true;
  119.             }
  120.         }
  121.         return $this->json([
  122.             'success' => $success,
  123.             'message' => $message,
  124.             'reason' => $reason ?? null,
  125.             'token' => $token ?? false
  126.         ]);
  127.     }
  128.     #[Route('/deconnexion'name'user_logout')]
  129.     public function logout(){}
  130.     #[Route('/reintegration'name'user_stop_anonymous')]
  131.     public function stopAnonymous(Request $requestUserAnonymousRepository $userAnonymousRepositoryEntityManagerInterface $manager): Response
  132.     {
  133.         if ($request->getMethod() == "POST") {
  134.             /* @var User $user */
  135.             $user $this->getUser();
  136.             $userAnonymousQuery $userAnonymousRepository->getUser($user);
  137.             $userAnonymous $userAnonymousQuery[0];
  138.             $user->setFirstname($userAnonymous->getFirstname())
  139.                 ->setLastname($userAnonymous->getLastname())
  140.                 ->setSlugUser($userAnonymous->getSlugUser())
  141.                 ->setCover($userAnonymous->getCover())
  142.                 ->setAvatar($userAnonymous->getAvatar())
  143.                 ->setPhone($userAnonymous->getPhone())
  144.                 ->setStatus('online')
  145.                 ->setAnonymousAt(null);
  146.             $manager->remove($userAnonymous);
  147.             $manager->flush();
  148.             $this->addFlash("success""Nous sommes ravi de vous revoir");
  149.             return $this->redirectToRoute('feed');
  150.         }
  151.         return $this->render('front/shared/anonymous.html.twig');
  152.     }
  153.     #[Route('/sensibility-details'name'sensibility_details')]
  154.     public function getSensibilityDetails(Request $requestSensibilityRepository $sensibilityRepository): JsonResponse
  155.     {
  156.         $data json_decode($request->getContent(), true);
  157.         $sensibility $sensibilityRepository->find($data['sensibilityId']);
  158.         if ($sensibility) {
  159.             return new JsonResponse([
  160.                 'status' => 'success',
  161.                 'title' => $sensibility->getTitle(),
  162.                 'description' => $sensibility->getDescription()
  163.             ]);
  164.         }
  165.         return new JsonResponse([
  166.             'status' => 'error',
  167.         ]);
  168.     }
  169.     #[Route('/save-user-profile-photo'name'save_user_profile')]
  170.     public function saveProfileImage(ImageOptimizer $imageOptimizerRequest $requestEntityManagerInterface $manager): JsonResponse
  171.     {
  172.         if ($request->isXmlHttpRequest()){
  173.             $user $this->getUser();
  174.             // the file
  175.             $file $_FILES['file'];
  176.             $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type']);
  177.             $filename $this->generateUniqueName() . '.' $file->guessExtension();
  178.             $imageOptimizer->resizeImage($file$filename'profiles_directory''avatar');
  179.             /*
  180.             $file->move(
  181.                 $this->getParameter('profiles_directory'),
  182.                 $filename
  183.             );
  184.             */
  185.             $oldProfile $user->getAvatar();
  186.             if ($oldProfile != 'default-profile.png' && file_exists($this->getParameter('profiles_directory').'/'.$oldProfile)  && is_file($this->getParameter('profiles_directory').'/'.$oldProfile)) {
  187.                 unlink($this->getParameter('profiles_directory').'/'.$oldProfile);
  188.             }
  189.             $user->setAvatar($filename);
  190.             $manager->persist($user);
  191.             $manager->flush();
  192.             $this->addFlash(
  193.                 'success',
  194.                 "Votre photo de profil à été modifiée"
  195.             );
  196.             return new JsonResponse("success");
  197.         }
  198.         return new JsonResponse("This is not an ajax request");
  199.     }
  200.     #[Route('/save-user-cover-photo'name'save_user_cover')]
  201.     public function saveCoverImage(ImageOptimizer $imageOptimizerRequest $requestEntityManagerInterface $manager): JsonResponse
  202.     {
  203.         if ($request->isXmlHttpRequest()){
  204.             $user $this->getUser();
  205.             // the file
  206.             $file $_FILES['file'];
  207.             $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type']);
  208.             $filename $this->generateUniqueName() . '.' $file->guessExtension();
  209.             $imageOptimizer->resizeImage($file$filename'profiles_directory''cover');
  210.             
  211.             /*
  212.             $file->move(
  213.                 $this->getParameter('profiles_directory'),
  214.                 $filename
  215.             );
  216.             */
  217.             $oldProfile $user->getCover();
  218.             if ($oldProfile != 'default-cover.png' && file_exists($this->getParameter('profiles_directory').'/'.$oldProfile)  && is_file($this->getParameter('profiles_directory').'/'.$oldProfile)) {
  219.                 unlink($this->getParameter('profiles_directory').'/'.$oldProfile);
  220.             }
  221.             $user->setCover($filename);
  222.             $manager->persist($user);
  223.             $manager->flush();
  224.             $this->addFlash(
  225.                 'success',
  226.                 "Votre photo de couverture à été modifiée"
  227.             );
  228.             return new JsonResponse("success");
  229.         }
  230.         return new JsonResponse("This is not an ajax request");
  231.     }
  232.     #[Route('/mon-profil/parametres'name'user_parameters')]
  233.     public function parameters(Request $requestEntityManagerInterface $managerUserPasswordHasherInterface $passwordHasherTestamentRepository $testamentRepository): Response
  234.     {
  235.         /**
  236.          * @var $user User
  237.          */
  238.         $user $this->getUser();
  239.         // Change password
  240.         $changepassword = new ChangePassword;
  241.         $formPassword $this->createForm(ChangePasswordType::class, $changepassword);
  242.         $formPassword->handleRequest($request);
  243.         if($formPassword->isSubmitted() && $formPassword->isValid()){
  244.             if(password_verify($changepassword->getCurrentPassword(), $user->getPassword())){
  245.                 $user->setPassword($passwordHasher->hashPassword($user$changepassword->getPassword()));
  246.                 $manager->persist($user);
  247.                 $manager->flush();
  248.                 $this->addFlash('success''Votre mot de passe a bien été modifié');
  249.                 return $this->redirectToRoute('user_parameters');
  250.             }
  251.             else{
  252.                 $formPassword->get('currentPassword')->addError(new FormError("Le mot de passe actuel est incorrect"));
  253.             }
  254.         }
  255.         if ($user->getType() == "politician") {
  256.             $testament $testamentRepository->findOneBy(['politician' => $user]);
  257.             if (!$testament) { $testament = new Testament(); }
  258.             $formTestament $this->createForm(TestamentType::class, $testament);
  259.             $formTestament->handleRequest($request);
  260.             if ($formTestament->isSubmitted() && $formTestament->isValid()) {
  261.                 $testament->setPolitician($user)
  262.                         ->setUpdateAt(new DateTime());
  263.                 $this->manager->persist($testament);
  264.                 $this->manager->flush();
  265.                 $this->addFlash("success""Votre testament à bien été enregistré");
  266.                 return $this->redirectToRoute('user_parameters');
  267.             }
  268.         }
  269.         // Handle confidentiality
  270.         $parameter $user->getParameter();
  271.         $formParameter $this->createForm(ParameterType::class, $parameter);
  272.         $formParameter->handleRequest($request);
  273.         if ($formParameter->isSubmitted() && $formParameter->isValid()) {
  274.             $manager->persist($parameter);
  275.             $manager->flush();
  276.             $this->addFlash('success''Vos paramètres de confidentialité ont été mis à jour');
  277.             return $this->redirectToRoute('user_parameters');
  278.         }
  279.         /* Contact form */
  280.         $contact = new Contact();
  281.         $formContact $this->createForm(ContactType::class, $contact);
  282.         $formContact->handleRequest($request);
  283.         if ($formContact->isSubmitted() && $formContact->isValid()) {
  284.             $contact->setUser($this->getUser());
  285.             $manager->persist($contact);
  286.             $manager->flush();
  287.             $this->addFlash("success""Votre demande a bien été envoyé");
  288.             return $this->redirect($request->getUri());
  289.         }
  290.         return $this->render('front/shared/parameters.html.twig', [
  291.             'menu' => 'parameters',
  292.             'showing' => 'owner',
  293.             'user' => $user,
  294.             'type' => $user->getType(),
  295.             'formPassword' => $formPassword->createView(),
  296.             'formParameter' => $formParameter->createView(),
  297.             'formContact' => $formContact->createView(),
  298.             'formTestament' => isset($formTestament) ? $formTestament->createView() : null
  299.         ]);
  300.     }
  301.     #[Route('/profil/{slugUser}'name'public_profile')]
  302.     public function showProfil(ToAdmin $toAdminUser $userPostRepository $postRepoRequest $request): Response
  303.     {
  304.         if ($user->getStatus() != "online") { return $this->redirectToRoute('feed'); }
  305.         if ($user === $this->getUser()) { return $this->redirectToRoute('owner_profile'); }
  306.         if ($user->getType() == "politician") {
  307.         
  308.             $suggestion = new Suggestion();
  309.             $suggestionForm $this->createForm(CitizenSuggestionType::class, $suggestion);
  310.             $suggestionForm->handleRequest($request);
  311.             if ($suggestionForm->isSubmitted() && $suggestionForm->isValid()) {
  312.                 
  313.                 $suggestion->setCreatedAt(new DateTimeImmutable())
  314.                             ->setPolitician($user)
  315.                             ->setStatus('pending')
  316.                             ->setCitizen($this->getUser())
  317.                             ->setShowPublic(true);
  318.                 $this->manager->persist($suggestion);
  319.                 $this->manager->flush();
  320.                 $toAdmin->newSuggestion($suggestion);
  321.                 
  322.                 $this->addFlash("success""Votre suggestion a bien été enregistrée");
  323.                 return $this->redirect($request->getUri());
  324.             }
  325.         }
  326.         else {
  327.             $suggestionForm $this->createForm(CitizenSuggestionType::class);
  328.         }
  329.         $posts $postRepo->feedByUserAccount($user);
  330.         return $this->render('front/shared/public-profile.html.twig', [
  331.             'showing' => 'public',
  332.             'user' => $user,
  333.             'type' => $user->getType(),
  334.             'posts' => $posts,
  335.             'suggestionForm' => $suggestionForm->createView(),
  336.             'totalPost' => $postRepo->feedByUserAccountCount($user),
  337.             'postSubmenu' => false
  338.         ]);
  339.     }
  340.     #[Route('/mon-profil'name'owner_profile')]
  341.     public function ownProfile(PostRepository $postRepoRequest $requestEntityManagerInterface $managerPoliticianRepository $politicianRepo): Response
  342.     {
  343.         /** @var User $user */
  344.         $user $this->getUser();
  345.         if ($user->getStatus() == "banned" || $user->getStatus() == "anonymous") { return $this->redirectToRoute('user_logout'); }
  346.         $posts $postRepo->feedByUserAccount($user);
  347.         $post = new Post();
  348.         $post->setHandleRedirect('profile');
  349.         $form $this->createForm(PostType::class, $post, [
  350.             'action' => $this->generateUrl('handle_post_submit')
  351.         ]);
  352.         $form->handleRequest($request);
  353.         if ($request->request->get('testament')) {
  354.             
  355.             $user->setTestamentText($request->request->get('testament'))
  356.                  ->setTestamentUpdatedAt(new DateTimeImmutable());
  357.             $manager->persist($user);
  358.             $manager->flush();
  359.             $this->addFlash("success""Votre testament a bien été enregistré");
  360.             return $this->redirectToRoute('owner_profile');            
  361.         }
  362.         if ($request->request->get('supportedName')) {
  363.             
  364.             $user->setSupported($request->request->get('supportedName'));
  365.             if ($request->request->get('supportedId') && $politicianRepo->find($request->request->get('supportedId'))) {
  366.                 
  367.                 $politicianSupported $politicianRepo->find($request->request->get('supportedId'));
  368.                 $user->setPoliticianSupported($politicianSupported);
  369.             }
  370.             else {
  371.                 $user->setPoliticianSupported(null);
  372.             }
  373.             $manager->persist($user);
  374.             $manager->flush();
  375.             $this->addFlash("success""Votre soutien a bien été enregistré");
  376.             return $this->redirectToRoute('owner_profile'); 
  377.         }
  378.         return $this->render('front/shared/owner-profile.html.twig', [
  379.             'menu' => 'profile',
  380.             'showing' => 'owner',
  381.             'user' => $user,
  382.             'type' => $user->getType(),
  383.             'posts' => $posts,
  384.             'form' => $form->createView(),
  385.             'totalPost' => $postRepo->feedByUserAccountCount($user),
  386.             'postSubmenu' => false
  387.         ]);
  388.     }
  389.     #[Route('/mon-profil/mise-a-jour/partie-politique'name'update_political_party'methods"POST")]
  390.     public function updatePoliticalParty(Request $requestPoliticalPartyRepository $politicalPartyRepository): Response
  391.     {
  392.         $message "Une erreur est survenue";
  393.         if ($request->get('politicalParty'))
  394.         {
  395.             $party $politicalPartyRepository->find($request->get('politicalParty'));
  396.             if ($party)
  397.             {
  398.                 /**
  399.                  * @var User $user
  400.                  **/
  401.                 $user $this->getUser();
  402.                 $user->setPoliticalParty($party);
  403.                 $this->manager->flush();
  404.                 $message "Vos informations on bien été modifié";
  405.             }
  406.         }
  407.         $this->addFlash("success"$message);
  408.         return $this->redirectToRoute('politician_owner_informations');
  409.     }
  410.     #[Route('/verification-email'name'verify_email_page')]
  411.     public function verifyEmailPage(): Response
  412.     {
  413.         return $this->render('front/registration/verify-email.html.twig');
  414.     }
  415.     #[Route('/compte-verification/{token}'name'verify_email')]
  416.     public function verifyEmail(User $userEntityManagerInterface $manager): Response
  417.     {
  418.         $user->setIsVerified(true)
  419.             ->setStatus('online');
  420.         $manager->flush();
  421.         $this->addFlash("success""Bienvenue sur Politicly");
  422.         return $this->redirectToRoute('owner_profile');
  423.     }
  424.     #[Route("/mot-de-passe-oublie"name:'forgot_password')]
  425.     public function forgotPassword(UserRepository $userRepositoryToUser $toUser): Response
  426.     {
  427.         $email null;
  428.         if (isset($_POST['forgot_submit'])) {
  429.             $email $_POST['forgot_email'];
  430.             $user $userRepository->findOneBy(['email' => $email]);
  431.             if ($user) {
  432.                 $toUser->forgotPassword($user);
  433.                 $email null;
  434.             }
  435.             $this->addFlash("success""Envoyé");
  436.             return $this->redirectToRoute('forgot_password');
  437.         }
  438.         
  439.         return $this->render('front/shared/forgot-password.html.twig', [
  440.             'email' => $email
  441.         ]);
  442.     }
  443.     #[Route("/reinitialisation-mot-de-passe/{token}"name:"admin_reset_password")]
  444.     public function resetPassword($tokenUserRepository $userRepositoryUserPasswordEncoderInterface $encoderRequest $requestEntityManagerInterface $manager): Response
  445.     {
  446.         $user $userRepository->findOneBy(['token' => $token]);
  447.         if ($user) {
  448.             $action 'reset';
  449.             $newPassword = new ResetPassword();
  450.             $form $this->createForm(ResetPasswordType::class, $newPassword);
  451.             $form->handleRequest($request);
  452.             if ($form->isSubmitted() && $form->isValid()) {
  453.                 $hashed $encoder->encodePassword($user$newPassword->getPassword());
  454.                 $user->setPassword($hashed)
  455.                     ->setToken($this->generateToken());
  456.                 $manager->persist($user);
  457.                 $manager->flush();
  458.                 $this->addFlash("success""Votre mot de passe a bien été modifié");
  459.                 return $this->redirectToRoute('user_welcome');
  460.             }
  461.             return $this->render('front/shared/reset-password.html.twig', [
  462.                 'action' => $action,
  463.                 'form' => $form->createView()
  464.             ]);
  465.         }
  466.         else {
  467.             $action 'expired';
  468.             return $this->render('front/shared/reset-password.html.twig', [
  469.                 'action' => $action
  470.             ]);
  471.         }
  472.     }
  473.     #[Route('/user/anonymisation/{slugUser}'name'user_anonymous'methods"POST")]
  474.     public function anonymousAccount(User $userEntityManagerInterface $managerRequest $requestUserPasswordHasherInterface $passwordHasher): Response
  475.     {
  476.         if ($this->getUser() !== $user) { return $this->redirectToRoute('user_logout'); }
  477.         if (!$passwordHasher->isPasswordValid($user$request->get('password'))) {
  478.             $this->addFlash("success""Mot de passe incorrect");
  479.             return $this->redirectToRoute('user_parameters');
  480.         }
  481.         $userAnonymous = new UserAnonymous();
  482.         $userAnonymous->setLastname($user->getLastname())
  483.             ->setFirstname($user->getFirstname())
  484.             ->setCover($user->getCover())
  485.             ->setAvatar($user->getAvatar())
  486.             ->setSlugUser($user->getSlugUser())
  487.             ->setPhone($user->getPhone())
  488.             ->setUser($user)
  489.         ;
  490.         $manager->persist($userAnonymous);
  491.         $date = new DateTimeImmutable('+1 month');
  492.         $user->setStatus('anonymous')
  493.             ->setFirstname('user anonyme')
  494.             ->setLastname('user anonyme')
  495.             ->setCover('default-cover.png')
  496.             ->setAvatar('default-profile.png')
  497.             ->setPhone(null)
  498.             ->setAnonymousAt($date)
  499.         ;
  500.         $manager->flush();
  501.         return $this->redirectToRoute('user_logout');
  502.     }
  503.     #[Route('/user/anonymisation/reset/{slugUser}'name'user_anonymous_reset')]
  504.     public function anonymousResetAccount(User $user): Response
  505.     {
  506.         if ($this->getUser() !== $user) { return $this->redirectToRoute('user_logout'); }
  507.         $user->setStatus("online")
  508.             ->setAnonymousAt(null);
  509.         $this->addFlash("success""C'est un plaisir de vous revoir parmi nous");
  510.         return $this->redirectToRoute('public_profile', ['slugUser' => $user->getSlugUser()]);
  511.     }
  512.     #[Route('/user/refuse/invitation/{slugUser}'name'user_refused_invitation')]
  513.     public function refuseInvitation(User $userEntityManagerInterface $managerFriendRepository $friendRepository): Response
  514.     {
  515.         $friend $friendRepository->findOneBy(["sender" => $user"receiver" => $this->getUser()]);
  516.         if ($friend) {
  517.             $friend->setStatus("refused");
  518.             $manager->flush();
  519.         }
  520.         $friendReverse $friendRepository->findOneBy(["receiver" => $user"sender" => $this->getUser()]);
  521.         if ($friendReverse) {
  522.             $manager->remove($friendReverse);
  523.             $manager->flush();
  524.         }
  525.         $this->addFlash("success""L'invitation à bien été supprimée");
  526.         return $this->redirectToRoute('public_profile', ['slugUser' => $user->getSlugUser()]);
  527.     }
  528.     #[Route('/user/accept/invitation/{slugUser}'name'user_accept_invitation')]
  529.     public function acceptInvitation(MessageBusInterface $busUser $userEntityManagerInterface $managerFriendRepository $friendRepository): Response
  530.     {
  531.         $friend $friendRepository->findOneBy(["sender" => $user"receiver" => $this->getUser()]);
  532.         if ($friend) {
  533.             $friend->setStatus("accepted");
  534.             
  535.             $notification = new Notification;
  536.             $notification->setType('friend')
  537.                         ->setOwner($friend->getSender())
  538.                         ->setRelatedUser($friend->getReceiver())
  539.                         ->setContent('a accepté votre demande de connexion')
  540.                         ->setIsOpened(false)
  541.                         ->setLink($this->generateUrl('public_profile', ['slugUser' => $friend->getReceiver()->getSlugUser()]))
  542.                         ->setCreatedAt(new DateTime());
  543.             $notification->getOwner()->setNotificationsOpen(false);
  544.             $manager->persist($notification);
  545.             $notificationOwnerId $notification->getOwner()->getId();
  546.             $update = new Update(
  547.                 "https://example.com/notifications/$notificationOwnerId",
  548.                 json_encode(['notification' => true])
  549.             );
  550.             try {
  551.                 $bus->dispatch($update);
  552.             } catch (\Exception) {}
  553.             $manager->flush();
  554.         }
  555.         $this->addFlash("success""L'invitation à bien été acceptée");
  556.         return $this->redirectToRoute('public_profile', ['slugUser' => $friend->getSender()->getSlugUser()]);
  557.     }
  558.     #[Route('/user/cancel/relation/{slugUser}'name'user_cancel_invitation')]
  559.     public function cancelRelation(User $userEntityManagerInterface $managerFriendRepository $friendRepository): Response
  560.     {
  561.         $friend $friendRepository->findOneBy(["sender" => $user"receiver" => $this->getUser()]);
  562.         if ($friend) {
  563.             $manager->remove($friend);
  564.             $manager->flush();
  565.         }
  566.         $friendReverse $friendRepository->findOneBy(["receiver" => $user"sender" => $this->getUser()]);
  567.         if ($friendReverse) {
  568.             $manager->remove($friendReverse);
  569.             $manager->flush();
  570.         }
  571.         $this->addFlash("success""La relation à bien été supprimée");
  572.         return $this->redirectToRoute('public_profile', ['slugUser' => $user->getSlugUser()]);
  573.     }
  574. }