diff options
Diffstat (limited to 'src/controller')
| -rw-r--r-- | src/controller/ContactFormController.php | 27 | ||||
| -rw-r--r-- | src/controller/PageManagementController.php | 17 | ||||
| -rw-r--r-- | src/controller/UserController.php | 6 |
3 files changed, 27 insertions, 23 deletions
diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php index 6b89161..cbc1837 100644 --- a/src/controller/ContactFormController.php +++ b/src/controller/ContactFormController.php | |||
| @@ -4,13 +4,15 @@ | |||
| 4 | declare(strict_types=1); | 4 | declare(strict_types=1); |
| 5 | 5 | ||
| 6 | use Doctrine\ORM\EntityManager; | 6 | use Doctrine\ORM\EntityManager; |
| 7 | use App\Entity\EmailForm; | ||
| 8 | use App\Entity\Email; | ||
| 7 | use Symfony\Component\HttpFoundation\JsonResponse; | 9 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 8 | 10 | ||
| 9 | class ContactFormController | 11 | class ContactFormController |
| 10 | { | 12 | { |
| 11 | static public function keepEmails(EntityManager $entityManager, array $json): JsonResponse | 13 | static public function keepEmails(EntityManager $entityManager, array $json): JsonResponse |
| 12 | { | 14 | { |
| 13 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 15 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 14 | $form_data->updateData('keep_emails', $json['checked'] ? true : false); | 16 | $form_data->updateData('keep_emails', $json['checked'] ? true : false); |
| 15 | $entityManager->persist($form_data); | 17 | $entityManager->persist($form_data); |
| 16 | $entityManager->flush(); | 18 | $entityManager->flush(); |
| @@ -18,7 +20,7 @@ class ContactFormController | |||
| 18 | } | 20 | } |
| 19 | static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): JsonResponse | 21 | static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): JsonResponse |
| 20 | { | 22 | { |
| 21 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 23 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 22 | $form_data->updateData($json['field'], (int)$json['months']); | 24 | $form_data->updateData($json['field'], (int)$json['months']); |
| 23 | $entityManager->persist($form_data); | 25 | $entityManager->persist($form_data); |
| 24 | $entityManager->flush(); | 26 | $entityManager->flush(); |
| @@ -28,22 +30,15 @@ class ContactFormController | |||
| 28 | { | 30 | { |
| 29 | $form = new FormValidation($json, 'email_params'); | 31 | $form = new FormValidation($json, 'email_params'); |
| 30 | 32 | ||
| 31 | $error = ''; | ||
| 32 | if($form->validate()){ | 33 | if($form->validate()){ |
| 33 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 34 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 34 | $form_data->updateData($json['what_param'], trim($json['value'])); | 35 | $form_data->updateData($json['what_param'], trim($json['value'])); |
| 35 | $entityManager->persist($form_data); | 36 | $entityManager->persist($form_data); // ?? |
| 36 | $entityManager->flush(); | 37 | $entityManager->flush(); |
| 37 | } | ||
| 38 | else{ | ||
| 39 | $error = $form->getErrors()[0]; // la 1ère erreur sera affichée | ||
| 40 | } | ||
| 41 | |||
| 42 | if(empty($error)){ | ||
| 43 | return new JsonResponse(['success' => true]); | 38 | return new JsonResponse(['success' => true]); |
| 44 | } | 39 | } |
| 45 | else{ | 40 | else{ |
| 46 | return new JsonResponse(['success' => false, 'error' => $error]); | 41 | return new JsonResponse(['success' => false, 'error' => $form->getErrors()[0]]); // la 1ère erreur sera affichée |
| 47 | } | 42 | } |
| 48 | } | 43 | } |
| 49 | 44 | ||
| @@ -55,7 +50,7 @@ class ContactFormController | |||
| 55 | $error = ''; | 50 | $error = ''; |
| 56 | if($form->validate()){ | 51 | if($form->validate()){ |
| 57 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | 52 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur |
| 58 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 53 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 59 | if($form_data === null){ | 54 | if($form_data === null){ |
| 60 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 | 55 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 |
| 61 | } | 56 | } |
| @@ -78,7 +73,7 @@ class ContactFormController | |||
| 78 | static public function sendTestEmail(EntityManager $entityManager, array $json): JsonResponse | 73 | static public function sendTestEmail(EntityManager $entityManager, array $json): JsonResponse |
| 79 | { | 74 | { |
| 80 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | 75 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur |
| 81 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 76 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 82 | if($form_data === null){ | 77 | if($form_data === null){ |
| 83 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); | 78 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); |
| 84 | } | 79 | } |
| @@ -92,14 +87,14 @@ class ContactFormController | |||
| 92 | } | 87 | } |
| 93 | static public function deleteEmail(EntityManager $entityManager, array $json): JsonResponse | 88 | static public function deleteEmail(EntityManager $entityManager, array $json): JsonResponse |
| 94 | { | 89 | { |
| 95 | $email = $entityManager->find('App\Entity\Email', $json['id']); | 90 | $email = $entityManager->find(Email::class, $json['id']); |
| 96 | $entityManager->remove($email); | 91 | $entityManager->remove($email); |
| 97 | $entityManager->flush(); | 92 | $entityManager->flush(); |
| 98 | return new JsonResponse(['success' => true]); | 93 | return new JsonResponse(['success' => true]); |
| 99 | } | 94 | } |
| 100 | static public function toggleSensitiveEmail(EntityManager $entityManager, array $json): JsonResponse | 95 | static public function toggleSensitiveEmail(EntityManager $entityManager, array $json): JsonResponse |
| 101 | { | 96 | { |
| 102 | $email = $entityManager->find('App\Entity\Email', $json['id']); | 97 | $email = $entityManager->find(Email::class, $json['id']); |
| 103 | $email->makeSensitive($json['checked']); | 98 | $email->makeSensitive($json['checked']); |
| 104 | $entityManager->flush(); | 99 | $entityManager->flush(); |
| 105 | return new JsonResponse(['success' => true, 'checked' => $json['checked'], 'deletion_date' => $email->getDeletionDate()->format('d/m/Y')]); | 100 | return new JsonResponse(['success' => true, 'checked' => $json['checked'], 'deletion_date' => $email->getDeletionDate()->format('d/m/Y')]); |
diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index a43f36c..c575077 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php | |||
| @@ -6,6 +6,7 @@ declare(strict_types=1); | |||
| 6 | use App\Entity\Page; | 6 | use App\Entity\Page; |
| 7 | use App\Entity\Node; | 7 | use App\Entity\Node; |
| 8 | use App\Entity\NodeData; | 8 | use App\Entity\NodeData; |
| 9 | use App\Entity\EmailForm; | ||
| 9 | //use App\Entity\Image; | 10 | //use App\Entity\Image; |
| 10 | use Doctrine\ORM\EntityManager; | 11 | use Doctrine\ORM\EntityManager; |
| 11 | use Symfony\Component\HttpFoundation\InputBag; | 12 | use Symfony\Component\HttpFoundation\InputBag; |
| @@ -144,7 +145,9 @@ class PageManagementController | |||
| 144 | } | 145 | } |
| 145 | 146 | ||
| 146 | $block = new Node($request->request->get("bloc_select"), $position, $main, $page); | 147 | $block = new Node($request->request->get("bloc_select"), $position, $main, $page); |
| 147 | $data = new NodeData(['title' => trim(htmlspecialchars($request->request->get("bloc_title")))], $block); | 148 | |
| 149 | $DataClass = $request->request->get("bloc_select") === 'form' ? EmailForm::class : NodeData::class; // cas particulier avec bloc 'email_form' | ||
| 150 | $data = new $DataClass(['title' => trim(htmlspecialchars($request->request->get("bloc_title")))], $block); | ||
| 148 | 151 | ||
| 149 | // valeurs par défaut | 152 | // valeurs par défaut |
| 150 | if($request->request->get("bloc_select") === 'post_block'){ | 153 | if($request->request->get("bloc_select") === 'post_block'){ |
| @@ -200,8 +203,15 @@ class PageManagementController | |||
| 200 | if(isset($page)){ | 203 | if(isset($page)){ |
| 201 | $entityManager->persist($page); | 204 | $entityManager->persist($page); |
| 202 | } | 205 | } |
| 206 | $block->getNodeData()->setNode(null); | ||
| 203 | $entityManager->remove($block); | 207 | $entityManager->remove($block); |
| 204 | $entityManager->flush(); | 208 | try{ |
| 209 | $entityManager->flush(); | ||
| 210 | } | ||
| 211 | catch(Exception $e){ | ||
| 212 | // utiliser une flash error | ||
| 213 | return new RedirectResponse((string)new URL(['page' => $request->query->get('page'), 'mode' => 'page_modif', 'error' => $e->getMessage()])); | ||
| 214 | } | ||
| 205 | } | 215 | } |
| 206 | 216 | ||
| 207 | return new RedirectResponse((string)new URL(['page' => $request->query->get('page'), 'mode' => 'page_modif'])); | 217 | return new RedirectResponse((string)new URL(['page' => $request->query->get('page'), 'mode' => 'page_modif'])); |
| @@ -277,8 +287,7 @@ class PageManagementController | |||
| 277 | $chrono_order = false; | 287 | $chrono_order = false; |
| 278 | } | 288 | } |
| 279 | else{ | 289 | else{ |
| 280 | echo json_encode(['success' => false]); | 290 | return new JsonResponse(['success' => false]); |
| 281 | die; | ||
| 282 | } | 291 | } |
| 283 | $model->getNode()->getNodeData()->setChronoOrder($chrono_order); | 292 | $model->getNode()->getNodeData()->setChronoOrder($chrono_order); |
| 284 | $entityManager->flush(); | 293 | $entityManager->flush(); |
diff --git a/src/controller/UserController.php b/src/controller/UserController.php index ddba33a..03686ee 100644 --- a/src/controller/UserController.php +++ b/src/controller/UserController.php | |||
| @@ -122,7 +122,7 @@ class UserController | |||
| 122 | $url = new URL; | 122 | $url = new URL; |
| 123 | isset($_GET['from']) ? $url->addParams(['page' => $_GET['from']]) : ''; | 123 | isset($_GET['from']) ? $url->addParams(['page' => $_GET['from']]) : ''; |
| 124 | isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; | 124 | isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; |
| 125 | return new RedirectResponse('Location: ' . $url); | 125 | return new RedirectResponse((string)$url); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | // user | 128 | // user |
| @@ -161,7 +161,7 @@ class UserController | |||
| 161 | sleep(1); | 161 | sleep(1); |
| 162 | $url->addParams(['error_username' => $error]); | 162 | $url->addParams(['error_username' => $error]); |
| 163 | } | 163 | } |
| 164 | return new RedirectResponse('Location: ' . $url); | 164 | return new RedirectResponse((string)$url); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | // user | 167 | // user |
| @@ -200,7 +200,7 @@ class UserController | |||
| 200 | sleep(1); | 200 | sleep(1); |
| 201 | $url->addParams(['error_password' => $error]); | 201 | $url->addParams(['error_password' => $error]); |
| 202 | } | 202 | } |
| 203 | return new RedirectResponse('Location: ' . $url); | 203 | return new RedirectResponse((string)$url); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | // dans une classe mère ou un trait après découpage de UserController? | 206 | // dans une classe mère ou un trait après découpage de UserController? |
