From f27cca08ff786ceff1870147f6d6bad14d71117f Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 23 Oct 2026 00:47:32 +0200 Subject: =?UTF-8?q?dossiers=20avec=20majuscule,=20namespace=20pour=20toute?= =?UTF-8?q?s=20les=20classes,=20autoload=20psr-4,=20UserDataService::creat?= =?UTF-8?q?eZip=20d=C3=A9plac=C3=A9=20dans=20Backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/ContactFormController.php | 107 +++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/Controller/ContactFormController.php (limited to 'src/Controller/ContactFormController.php') diff --git a/src/Controller/ContactFormController.php b/src/Controller/ContactFormController.php new file mode 100644 index 0000000..56ef402 --- /dev/null +++ b/src/Controller/ContactFormController.php @@ -0,0 +1,107 @@ +find(EmailForm::class, $json['id']); + $form_data->updateData('keep_emails', $json['checked'] ? true : false); + $entityManager->persist($form_data); + $entityManager->flush(); + return new JsonResponse(['success' => true, 'checked' => $json['checked']]); + } + static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): JsonResponse + { + $form_data = $entityManager->find(EmailForm::class, $json['id']); + $form_data->updateData($json['field'], (int)$json['months']); + $entityManager->persist($form_data); + $entityManager->flush(); + return new JsonResponse(['success' => true, 'months' => $json['months']]); + } + static public function setEmailParam(EntityManager $entityManager, array $json): JsonResponse + { + $form = new FormValidation($json, ValidationStrategy::EmailParam); + + if($form->validate()){ + $form_data = $entityManager->find(EmailForm::class, $json['id']); + $form_data->updateData($json['what_param'], trim($json['value'])); + $entityManager->persist($form_data); // ?? + $entityManager->flush(); + return new JsonResponse(['success' => true]); + } + else{ + return new JsonResponse(['success' => false, 'error' => $form->getError()]); + } + } + + // les deux méthodes suivantes sont "factorisables", elles ne se distinguent que par la gestion ou non du formulaire rempli par le visiteur + static public function sendVisitorEmail(EntityManager $entityManager, array $json): JsonResponse + { + $form = new FormValidation($json, ValidationStrategy::EmailSend); + + $error = ''; + if($form->validate()){ + // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur + $form_data = $entityManager->find(EmailForm::class, $json['id']); + if($form_data === null){ + return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 + } + + if(!EmailService::send($entityManager, $form_data, false, $form->getField('name'), $form->getField('email'), $form->getField('message'))){ + $error = 'email_not_sent'; + } + } + else{ + $error = $form->getError(); + } + + if(empty($error)){ + return new JsonResponse(['success' => true]); + } + else{ + return new JsonResponse(['success' => false, 'error' => $error]); + } + } + static public function sendTestEmail(EntityManager $entityManager, array $json): JsonResponse + { + // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur + $form_data = $entityManager->find(EmailForm::class, $json['id']); + if($form_data === null){ + return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); + } + + if(EmailService::send($entityManager, $form_data, true, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ + return new JsonResponse(['success' => true]); + } + else{ + return new JsonResponse(['success' => false, 'error' => 'email_not_sent']); + } + } + static public function deleteEmail(EntityManager $entityManager, array $json): JsonResponse + { + $email = $entityManager->find(Email::class, $json['id']); + $entityManager->remove($email); + $entityManager->flush(); + return new JsonResponse(['success' => true]); + } + static public function toggleSensitiveEmail(EntityManager $entityManager, array $json): JsonResponse + { + $email = $entityManager->find(Email::class, $json['id']); + $email->makeSensitive($json['checked']); + $entityManager->flush(); + return new JsonResponse(['success' => true, 'checked' => $json['checked'], 'deletion_date' => $email->getDeletionDate()->format('d/m/Y')]); + } +} \ No newline at end of file -- cgit v1.2.3