From 2caa43345c068fe24da8d14f2b067f6195fbcedf Mon Sep 17 00:00:00 2001 From: Audrey Jensen Date: Wed, 28 Jun 2023 20:01:17 +0000 Subject: [PATCH] add anonmous complaints --- .env | 2 +- src/Controller/ComplaintController.php | 64 ++++++++++++++++++++++++-- src/Form/AnonymousComplaintType.php | 28 +++++++++++ templates/complaint.html.twig | 37 +++++++++++++++ 4 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 src/Form/AnonymousComplaintType.php create mode 100644 templates/complaint.html.twig diff --git a/.env b/.env index 55d3e9b..d30cd33 100644 --- a/.env +++ b/.env @@ -38,5 +38,5 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 ###< symfony/messenger ### ###> symfony/mailer ### -# MAILER_DSN=null://null +MAILER_DSN=smtp://smtp.jv.com:25 ###< symfony/mailer ### diff --git a/src/Controller/ComplaintController.php b/src/Controller/ComplaintController.php index 5f910e3..e95bff9 100644 --- a/src/Controller/ComplaintController.php +++ b/src/Controller/ComplaintController.php @@ -1,18 +1,74 @@ render('portal.html.twig',$contentFile); + $form = $this->createForm(AnonymousComplaintType::class); + $form->handleRequest($request); + if($form->isSubmitted()) + { + $message = $form->get('Message')->getData(); + $email = (new Email()) + ->from(new Address('noreply@jv.com', 'Anonymous')) + ->to('ajensen@jv.com') //Send to me for testing purposes. TODO: change to chris@jv.com + ->subject('Anonymous Contact Form') + ->text($message); + $email->getHeaders()->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply'); //Tell autoresponders to not reply + try + { + + $log->Debug('Send email!'); + $mailer->send($email); //FIXME: Emails aren't sending for some reason + $isSubmitted = true; + } + catch (TransportExceptionInterface $e) + { + $isSubmitted = false; + } + } + else + { + $isSubmitted = null; + } + $headerFile = Yaml::parseFile('../config/portalLinks.yaml', 2, 2, Yaml::PARSE_OBJECT_FOR_MAP); + return $this->render('complaint.html.twig',['header' => $headerFile, 'form' => $form, 'isSubmitted' => $isSubmitted]); } + public function sendEmail(TransportTransportInterface $mailer, string $message, LoggerInterface $log) : bool + { + $email = (new Email()) + ->from(new Address('noreply@jv.com', 'Anonymous')) + ->to('ajensen@jv.com') //Send to me for testing purposes. TODO: change to chris@jv.com + ->subject('Anonymous Contact Form') + ->text($message); + $email->getHeaders()->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply'); //Tell autoresponders to not reply + try + { + $log->debug($mailer->send($email)->toString()); + return true; + } + catch (TransportExceptionInterface $e) + { + return false; + } + + } } \ No newline at end of file diff --git a/src/Form/AnonymousComplaintType.php b/src/Form/AnonymousComplaintType.php new file mode 100644 index 0000000..7beedb4 --- /dev/null +++ b/src/Form/AnonymousComplaintType.php @@ -0,0 +1,28 @@ +add('Message', TextareaType::class) + ->add('Submit', SubmitType::class) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + // Configure your form options here + ]); + } +} diff --git a/templates/complaint.html.twig b/templates/complaint.html.twig new file mode 100644 index 0000000..6eb5bde --- /dev/null +++ b/templates/complaint.html.twig @@ -0,0 +1,37 @@ + + + +{{ include('_header.html.twig') }} + + + + +
+

Anonymous Complaint Page +

Instructions

+ +

Type your complaint or problem into the message box below and click "Submit". +
Messages will be sent directly to Chris Weiser's email account. +
Messages will be completely anonymous so complaints cannot be traced to a specific person.
Feel free to submit any problem or concern.

+ +
+ {{ form(form) }} +
+ {% if isSubmitted != null %} + {% if isSubmitted %} +
Form submitted successfully
+ {% else %} +
Form failed to submit with errors
+ {% endif %} + {% else %} + Nah this broke //TODO: remove after debugging + {% endif %} +
+ + \ No newline at end of file