diff --git a/.env b/.env index 3486865..067e284 100644 --- a/.env +++ b/.env @@ -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' diff --git a/config/services.yaml b/config/services.yaml index 2cd1dfb..2f830aa 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -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 diff --git a/migrations/Version20240519140526.php b/migrations/Version20240519140526.php new file mode 100644 index 0000000..121d08b --- /dev/null +++ b/migrations/Version20240519140526.php @@ -0,0 +1,31 @@ +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'); + } +} diff --git a/src/Controller/Admin/MembershipApplicationCrud.php b/src/Controller/Admin/MembershipApplicationCrud.php index ab478db..f0003e7 100644 --- a/src/Controller/Admin/MembershipApplicationCrud.php +++ b/src/Controller/Admin/MembershipApplicationCrud.php @@ -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!") @@ -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, ]), ); diff --git a/src/Controller/MemberController.php b/src/Controller/MemberController.php index 6f227bc..b4e8b6e 100644 --- a/src/Controller/MemberController.php +++ b/src/Controller/MemberController.php @@ -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; @@ -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; } @@ -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()) @@ -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 diff --git a/src/Entity/MembershipApplication.php b/src/Entity/MembershipApplication.php index 35e9b13..d75a38a 100644 --- a/src/Entity/MembershipApplication.php +++ b/src/Entity/MembershipApplication.php @@ -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(); } @@ -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; } + } diff --git a/templates/email/html/apply.html.twig b/templates/email/html/apply.html.twig new file mode 100644 index 0000000..d2d6c74 --- /dev/null +++ b/templates/email/html/apply.html.twig @@ -0,0 +1,15 @@ +{% extends 'email/html/layout.html.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 %} diff --git a/templates/email/text/apply.txt.twig b/templates/email/text/apply.txt.twig new file mode 100644 index 0000000..c6cbb13 --- /dev/null +++ b/templates/email/text/apply.txt.twig @@ -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 %} diff --git a/templates/email/text/fresh_member.txt.twig b/templates/email/text/fresh_member.txt.twig new file mode 100644 index 0000000..df8c288 --- /dev/null +++ b/templates/email/text/fresh_member.txt.twig @@ -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 %}