forked from audrey/intranet
add anonmous complaints
This commit is contained in:
parent
632199009d
commit
2caa43345c
2
.env
2
.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 ###
|
||||
|
||||
@ -1,18 +1,74 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Form\AnonymousComplaintType;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use jv\intranet\Types\NavbarItem;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Symfony\Component\Mailer\TransportInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mailer\Transport\TransportInterface as TransportTransportInterface;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Mime\Address;
|
||||
|
||||
class ComplaintController extends AbstractController
|
||||
{
|
||||
#[Route('/complaint')]
|
||||
public function Index() : Response
|
||||
public function Index(Request $request, TransportTransportInterface $mailer,LoggerInterface $log) : Response
|
||||
{
|
||||
|
||||
$contentFile = Yaml::parseFile('../config/portalLinks.yaml', 2, 2, Yaml::PARSE_OBJECT_FOR_MAP);
|
||||
return $this->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
28
src/Form/AnonymousComplaintType.php
Normal file
28
src/Form/AnonymousComplaintType.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Doctrine\DBAL\Types\TextType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AnonymousComplaintType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('Message', TextareaType::class)
|
||||
->add('Submit', SubmitType::class)
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
// Configure your form options here
|
||||
]);
|
||||
}
|
||||
}
|
||||
37
templates/complaint.html.twig
Normal file
37
templates/complaint.html.twig
Normal file
@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
{{ include('_header.html.twig') }}
|
||||
|
||||
<body>
|
||||
<!-- Navigation -->
|
||||
<div class="siteNavbar">
|
||||
<ul class="list-group list-group-horizontal-md">
|
||||
{% for item in header.Navbar %}
|
||||
<h3 class="navitem"><a class=" list-group-item list-group-item-action text-decoration-none h-100 text-white border-0" href="{{item.url}}">{{item.title}}</a></h3>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="container">
|
||||
<h2>Anonymous Complaint Page
|
||||
<h4 class="text-bold">Instructions</h4>
|
||||
|
||||
<p>Type your complaint or problem into the message box below and click "Submit".
|
||||
<br>Messages will be sent directly to Chris Weiser's email account.
|
||||
<br>Messages will be completely anonymous so complaints cannot be traced to a specific person. <br> Feel free to submit any problem or concern.</p>
|
||||
|
||||
</div>
|
||||
{{ form(form) }}
|
||||
<div class="container">
|
||||
{% if isSubmitted != null %}
|
||||
{% if isSubmitted %}
|
||||
<h5 class="alert alert-success"> Form submitted successfully </h5>
|
||||
{% else %}
|
||||
<h5 class="alert alert-danger"> Form failed to submit with errors </h5>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
Nah this broke //TODO: remove after debugging
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user