Skip to content

Commit

Permalink
Merge pull request #181 from roodjong/141-emails
Browse files Browse the repository at this point in the history
Send new emails
  • Loading branch information
pingiun authored May 19, 2024
2 parents 29e7733 + 483abd5 commit 184c4b0
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ ORG_LOGO='assets/image/logo.png'
PRIVACY_POLICY_URL='https://roodjongeren.nl/privacybeleid/'
USE_MIDDLE_NAME=true
CONTRIBUTION_ENABLED=true
SEND_FRESH_MEMBER_EMAIL_TO_BOARD=true
SEND_FRESH_MEMBER_EMAIL_TO_DIVISION_EMAIL=false

# Set to https in production environment
SECURE_SCHEME='http'
3 changes: 3 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ parameters:
app.organizationName: '%env(ORGANIZATION_NAME)%'
app.organizationID: '%env(ORGANIZATION_ID)%'
app.noReplyAddress: '%env(NOREPLY_ADDRESS)%'
app.organizationEmail: '%env(ORGANIZATION_EMAIL)%'
app.homepageUrl: '%env(HOMEPAGE)%'
app.orgLogo: '%env(ORG_LOGO)%'
app.privacyPolicyUrl: '%env(PRIVACY_POLICY_URL)%'
app.useMiddleName: '%env(bool:USE_MIDDLE_NAME)%'
app.sendFreshMemberEmailToBoard: '%env(bool:SEND_FRESH_MEMBER_EMAIL_TO_BOARD)%'
app.sendFreshMemberEmailToDivisionEmail: '%env(bool:SEND_FRESH_MEMBER_EMAIL_TO_DIVISION_EMAIL)%'
app.contributionEnabled: '%env(bool:CONTRIBUTION_ENABLED)%'
router.request_context.scheme: '%env(SECURE_SCHEME)%'
asset.request_context.secure: true
Expand Down
31 changes: 31 additions & 0 deletions migrations/Version20240519140526.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240519140526 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE admin_membership_application ADD has_sent_initial_email TINYINT(1) DEFAULT 0 NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE admin_membership_application DROP has_sent_initial_email');
}
}
12 changes: 6 additions & 6 deletions src/Controller/Admin/MembershipApplicationCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ public function acceptApplication(AdminContext $context)
$em->remove($application);
$em->flush();

$templatePrefix = '';
$templatePrefix = '';

if (is_dir($this->getParameter('kernel.project_dir') . '/templates/custom')) {
$templatePrefix = 'custom/';
}
if (is_dir($this->getParameter('kernel.project_dir') . '/templates/custom')) {
$templatePrefix = 'custom/';
}

$message = (new Email())
->subject("Welkom bij $organizationName!")
Expand All @@ -156,12 +156,12 @@ public function acceptApplication(AdminContext $context)
->to(new Address($contact->getEmail(), $contact->getFullName()))
->from(new Address($noreply, $organizationName))
->html(
$this->renderView('email/html/contact_new_member.html.twig', [
$this->renderView($templatePrefix . 'email/html/contact_new_member.html.twig', [
'member' => $member,
]),
)
->text(
$this->renderView('email/text/contact_new_member.txt.twig', [
$this->renderView($templatePrefix . 'email/text/contact_new_member.txt.twig', [
'member' => $member,
]),
);
Expand Down
65 changes: 64 additions & 1 deletion src/Controller/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\{ Response, Request };
use Symfony\Component\Form\Extension\Core\Type\{ PasswordType, RepeatedType };
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
Expand All @@ -28,8 +31,9 @@ class MemberController extends AbstractController {

private MollieApiClient $mollieApiClient;

public function __construct(MollieApiClient $mollieApiClient)
public function __construct(MailerInterface $mailer, MollieApiClient $mollieApiClient)
{
$this->mailer = $mailer;
$this->mollieApiClient = $mollieApiClient;
}

Expand Down Expand Up @@ -166,6 +170,7 @@ private function createPayment(Customer $customer, float $contributionAmount) {
public function handleRedirect(Request $request, string $customerId): Response
{
$membershipApplicationRepository = $this->getDoctrine()->getRepository(MembershipApplication::class);
/** @var MembershipApplication $membershipApplication */
$membershipApplication = $membershipApplicationRepository->findOneByMollieCustomerId($customerId);

if ($membershipApplication !== null && $membershipApplication->getPaid())
Expand All @@ -175,6 +180,64 @@ public function handleRedirect(Request $request, string $customerId): Response
return $this->json(['success' => true]);
}

if (!$membershipApplication->getHasSentInitialEmail()) {
$templatePrefix = '';

if (is_dir($this->getParameter('kernel.project_dir') . '/templates/custom')) {
$templatePrefix = 'custom/';
}

$memberEmail = $membershipApplication->getEmail();
$memberFullName = $membershipApplication->getFullName();
$memberFirstName = $membershipApplication->getFirstName();

$noreplySender = $this->getParameter('app.noReplyAddress');
$emailSender = $this->getParameter('app.organizationEmail');
$organizationName = $this->getParameter('app.organizationName');
$message = (new Email())
->subject("Bedankt voor je aanmelding bij $organizationName!")
->to(new Address($memberEmail, $memberFullName))
->from(new Address($emailSender, $organizationName))
->html(
$this->renderView($templatePrefix . 'email/html/apply.html.twig', ['memberFirstName' => $memberFirstName])
)
->text(
$this->renderView($templatePrefix . 'email/text/apply.txt.twig', ['memberFirstName' => $memberFirstName])
);
$this->mailer->send($message);

if ($this->getParameter('app.sendFreshMemberEmailToBoard')) {
$message = (new Email())
->subject("Er is een nieuw lid die geaccepteerd kan worden")
->to(new Address($emailSender, $organizationName))
->from(new Address($noreplySender, "De website"))
->text(
$this->renderView($templatePrefix . 'email/text/fresh_member.txt.twig', ['memberFullName' => $memberFullName, 'memberEmail' => $memberEmail])
);
$this->mailer->send($message);
}

if ($this->getParameter('app.sendFreshMemberEmailToDivisionEmail')
&& $membershipApplication->getPreferredDivision() !== null
&& $membershipApplication->getPreferredDivision()->getEmail() !== null
) {
$division = $membershipApplication->getPreferredDivision();
$message = (new Email())
->subject("Er is een nieuw lid die geaccepteerd kan worden")
->to(new Address($division->getEmail(), $division->getName()))
->from(new Address($noreplySender, "De website"))
->text(
$this->renderView($templatePrefix . 'email/text/fresh_member.txt.twig', ['memberFullName' => $memberFullName, 'memberEmail' => $memberEmail])
);
$this->mailer->send($message);
}

$membershipApplication->setHasSentInitialEmail(true);
$em = $this->getDoctrine()->getManager();
$em->persist($membershipApplication);
$em->flush();
}

return $this->render('user/member/finished.html.twig');
}
else
Expand Down
8 changes: 8 additions & 0 deletions src/Entity/MembershipApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class MembershipApplication {
*/
private ?bool $paid = false;

/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $hasSentInitialEmail = false;

public function __construct() {
$this->registrationTime = new DateTime();
}
Expand Down Expand Up @@ -210,4 +215,7 @@ public function setContributionPeriod(int $contributionPeriod): void {
$this->contributionPeriod = $contributionPeriod;
}

public function getHasSentInitialEmail(): bool { return $this->hasSentInitialEmail; }
public function setHasSentInitialEmail(bool $hasSentInitialEmail): void { $this->hasSentInitialEmail = $hasSentInitialEmail; }

}
15 changes: 15 additions & 0 deletions templates/email/html/apply.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'email/html/layout.html.twig' %}
{% block content %}
<p>
Beste {{ memberFirstName }},
</p>
<p>
Bedankt voor het aanmelden bij {{ organisatienaam }}. De afdeling zal je aanmelding verwerken waarna u nog een bevestigingsmail zult ontvangen.
</p>
<p>
Kameraadschappelijke groet,
</p>
<p>
{{ organisatienaam }}
</p>
{% endblock %}
11 changes: 11 additions & 0 deletions templates/email/text/apply.txt.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'email/text/layout.txt.twig' %}
{% block content %}
Beste {{ memberFirstName }},

Bedankt voor het aanmelden bij {{ organisatienaam }}. De afdeling zal je aanmelding verwerken waarna u nog een bevestigingsmail zult ontvangen.

Kameraadschappelijke groet,

{{ organisatienaam }}

{% endblock %}
16 changes: 16 additions & 0 deletions templates/email/text/fresh_member.txt.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'email/text/layout.txt.twig' %}
{% block content %}
Hoi bestuur of lokaal bestuur,

Er heeft net een lid zich aangemeld op de website. Je kan dit lid nu goedkeuren of weigeren op de website.

Dit is de informatie van het nieuwe lid:

{{ memberFullName }}
{{ memberEmail }}

Kameraadschappelijke groet,

de website

{% endblock %}

0 comments on commit 184c4b0

Please sign in to comment.