summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2020-03-10 20:40:12 +1100
committerYingtong Li <runassudo@yingtongli.me>2020-03-10 21:13:53 +1100
commitfbe0396a8e1b6d03d0b479387aa84ae970b41cd5 (patch)
treeba12489d9ba7303a000e6ffeec9fea733d65f0b5
parentb725b46f2f676e5606725630fe82c2f6a5846ef1 (diff)
Add command to send renewal emails
-rw-r--r--ssmembership/jinja2/ssmembership/email/onboard.txt33
-rw-r--r--ssmembership/jinja2/ssmembership/email/renew.html (renamed from ssmembership/jinja2/ssmembership/email/onboard.html)24
-rw-r--r--ssmembership/jinja2/ssmembership/email/renew.txt31
-rw-r--r--ssmembership/management/commands/send_renewal_email.py73
4 files changed, 112 insertions, 49 deletions
diff --git a/ssmembership/jinja2/ssmembership/email/onboard.txt b/ssmembership/jinja2/ssmembership/email/onboard.txt
deleted file mode 100644
index 7bd3d4b..0000000
--- a/ssmembership/jinja2/ssmembership/email/onboard.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-{#
- Society Self-Service
- Copyright © 2018-2019 Yingtong Li (RunasSudo)
-
- Design by SendWithUs (Apache 2.0 licence)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-#}
-Dear {{ name }},
-
-{% if purchased %}Thank you for your recent purchase of a {{ import('django.conf').settings.ORG_NAME }} membership.{% else %}Thank you for your recent purchase of {{ import('django.conf').settings.ORG_NAME }} tickets or merchandise. Your purchase entitles you to membership of {{ import('django.conf').settings.ORG_NAME }} at no additional cost.{% endif %} You can activate your membership now by going to the link below or visiting {{ baseurl }}{{ url('monboard_index') }}. The process is very quick and should take less than a minute.
-
-By activating your membership, you'll be able to purchase future tickets at discounted member prices, nominate for election to the {{ import('django.conf').settings.ORG_NAME }} committee, and receive personalised weekly emails with relevant news and events from around the Monash Medicine community.
-
-Activate membership now:
-{{ baseurl }}{{ renew_url }}
-
-If you do not want to activate your membership, or you are not a Monash medical student, simply ignore this email.
-
-If you encounter any issues activating your membership, or have any other questions, please contact the Secretary, Yingtong Li, at {{ import('django.conf').settings.AWS_SENDER_EMAIL }}.
-
-Please note that emails are being sent in stages. If other students have not received this email, please let them know that this is normal, and they should receive their email within 7 days. Otherwise, contact {{ import('django.conf').settings.AWS_SENDER_EMAIL }}.
diff --git a/ssmembership/jinja2/ssmembership/email/onboard.html b/ssmembership/jinja2/ssmembership/email/renew.html
index 448faee..935d186 100644
--- a/ssmembership/jinja2/ssmembership/email/onboard.html
+++ b/ssmembership/jinja2/ssmembership/email/renew.html
@@ -2,7 +2,7 @@
{#
Society Self-Service
- Copyright © 2018-2019 Yingtong Li (RunasSudo)
+ Copyright © 2018-2020 Yingtong Li (RunasSudo)
Design by SendWithUs (Apache 2.0 licence)
@@ -26,23 +26,15 @@
<table>
<tr>
<th>
- <b><h5>Welcome to {{ import('django.conf').settings.ORG_NAME }}!</h5></b>
+ <b><h5>Membership renewal</h5></b>
<p>Dear {{ name }},</p>
- <p>
- {% if purchased %}
- Thank you for your recent purchase of a {{ import('django.conf').settings.ORG_NAME }} membership.
- {% else %}
- Thank you for your recent purchase of {{ import('django.conf').settings.ORG_NAME }} tickets or merchandise. Your purchase entitles you to membership of {{ import('django.conf').settings.ORG_NAME }} at no additional cost.
- {% endif %}
- You can activate your membership now by clicking the button below or visiting <a href="{{ baseurl }}{{ url('monboard_index') }}">{{ baseurl }}{{ url('monboard_index') }}</a>. The process is very quick and should take less than a minute.
- </p>
- <p>By activating your membership, you'll be able to purchase future tickets at discounted member prices, nominate for election to the {{ import('django.conf').settings.ORG_NAME }} committee, and receive personalised weekly emails with relevant news and events from around the Monash Medicine community.</p>
- <div class="button">
- <a href="{{ baseurl }}{{ renew_url }}" style="background-color:#f7931d;border:0px solid #f7931d;border-radius:3px;color:#ffffff;display:inline-block;font-family:sans-serif;font-size:16px;font-weight:bold;line-height:35px;text-align:center;text-decoration:none;width:300px;-webkit-text-size-adjust:none;mso-hide:all;">Activate membership now</a>
+ <p>{{ import('django.conf').settings.ORG_NAME }} is required by law to review its membership annually. You can renew your membership for free by clicking the button below or visiting <a href="{{ baseurl }}{{ url('renew_index') }}">{{ baseurl }}{{ url('renew_index') }}</a>. The process is very quick and should take less than a minute.</p>
+ <div class="button" style="margin-bottom:1em;">
+ <a href="{{ baseurl }}{{ renew_url }}" style="background-color:#f7931d;border:0px solid #f7931d;border-radius:3px;color:#ffffff;display:inline-block;font-family:sans-serif;font-size:16px;font-weight:bold;line-height:35px;text-align:center;text-decoration:none;width:300px;-webkit-text-size-adjust:none;mso-hide:all;">Renew membership now</a>
</div>
- <br>
- <p>If you do not want to activate your membership, or you are not a Monash medical student, simply ignore this email.</p>
- <p>If you encounter any issues activating your membership, or have any other questions, please contact the Secretary, Yingtong Li, at <a href="mailto:{{ import('django.conf').settings.AWS_SENDER_EMAIL }}">{{ import('django.conf').settings.AWS_SENDER_EMAIL }}</a>.</p>
+ <p>If you do not renew your membership by <b>31 March {{ import('datetime').datetime.now().strftime('%Y') }}</b>, your membership will expire, and you will not be able to buy tickets to {{ import('django.conf').settings.ORG_NAME }} events at member prices or run for election within {{ import('django.conf').settings.ORG_NAME }} without becoming a member again. If you would like to become a member again after that date, you can either purchase membership for $5, or purchase {{ import('django.conf').settings.ORG_NAME }} merchandise or a ticket to a {{ import('django.conf').settings.ORG_NAME }} event.</p>
+ <p>If you do not want to renew your membership, or you are no longer a Monash medical student, simply ignore this email.</p>
+ <p>If you encounter any issues renewing your membership, or have any other questions, please contact the Secretary, Dinali Panagodage, at <a href="mailto:{{ import('django.conf').settings.AWS_SENDER_EMAIL }}">{{ import('django.conf').settings.AWS_SENDER_EMAIL }}</a>.</p>
<p style="font-size: x-small;">Please note that emails are being sent in stages. If other students have not received this email, please let them know that this is normal, and they should receive their email within 7 days. Otherwise, contact <a href="mailto:{{ import('django.conf').settings.AWS_SENDER_EMAIL }}">{{ import('django.conf').settings.AWS_SENDER_EMAIL }}</a>.</p>
</th>
<th class="expander"></th>
diff --git a/ssmembership/jinja2/ssmembership/email/renew.txt b/ssmembership/jinja2/ssmembership/email/renew.txt
new file mode 100644
index 0000000..00d8ca3
--- /dev/null
+++ b/ssmembership/jinja2/ssmembership/email/renew.txt
@@ -0,0 +1,31 @@
+{#
+ Society Self-Service
+ Copyright © 2018-2020 Yingtong Li (RunasSudo)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+#}
+Dear {{ name }},
+
+{{ import('django.conf').settings.ORG_NAME }} is required by law to review its membership annually. You can renew your membership for free by going to the link below or visiting {{ baseurl }}{{ url('renew_index') }}. The process is very quick and should take less than a minute.
+
+Renew membership now:
+{{ baseurl }}{{ renew_url }}
+
+If you do not renew your membership by **31 March {{ import('datetime').datetime.now().strftime('%Y') }}**, your membership will expire, and you will not be able to buy tickets to MUMUS events at member prices or run for election within MUMUS without becoming a member again. Please make sure to renew your membership by 31 March {{ import('datetime').datetime.now().strftime('%Y') }} to avoid this.
+
+If you do not want to renew your membership, or you are no longer a Monash medical student, simply ignore this email.
+
+If you encounter any issues renewing your membership, or have any other questions, please contact the Secretary, Dinali Panagodage, at {{ import('django.conf').settings.AWS_SENDER_EMAIL }}.
+
+Please note that emails are being sent in stages. If other students have not received this email, please let them know that this is normal, and they should receive their email within 7 days. Otherwise, contact {{ import('django.conf').settings.AWS_SENDER_EMAIL }}.
diff --git a/ssmembership/management/commands/send_renewal_email.py b/ssmembership/management/commands/send_renewal_email.py
new file mode 100644
index 0000000..08e9f26
--- /dev/null
+++ b/ssmembership/management/commands/send_renewal_email.py
@@ -0,0 +1,73 @@
+# Society Self-Service
+# Copyright © 2018-2020 Yingtong Li (RunasSudo)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+from ssmain.email import Emailer
+
+from django.core.management.base import BaseCommand, CommandError
+
+from django.conf import settings
+from django.template import loader
+from django.urls import reverse
+from django.utils import timezone
+
+from ssmembership import models
+
+import hmac
+import logging
+import premailer
+import time
+import urllib.parse
+
+class Command(BaseCommand):
+ help = 'Send emails for membership renewal'
+
+ def add_arguments(self, parser):
+ parser.add_argument('ids', nargs='*', type=int, help='Members with ID numbers equal to these values will be emailed (default all)')
+ parser.add_argument('--render', action='store_true', help='Render to stdout instead of sending emails')
+
+ def handle(self, *args, **options):
+ today = timezone.localtime(timezone.now()).date()
+
+ template_html = loader.get_template('ssmembership/email/renew.html')
+ template_txt = loader.get_template('ssmembership/email/renew.txt')
+
+ if len(options['ids']) > 0:
+ members = models.Member.objects.filter(id__in=options['ids'])
+ else:
+ raise Exception('Must provide IDs')
+
+ emailer = Emailer()
+ for member in members:
+ #import pdb; pdb.set_trace()
+ if member.member_type != 1 or member.expires < today or member.expires > today.replace(month=12, day=31):
+ self.stdout.write('Skipping {} at {}'.format(member.id, member.email))
+ continue
+
+ self.stdout.write('Emailing {} at {}'.format(member.id, member.email))
+
+ sig = hmac.new(settings.SECRET_KEY_MEMBERSIG.encode('utf-8'), member.email.encode('utf-8'), 'sha256').hexdigest()
+ renew_url = reverse('renew_signed') + '?' + urllib.parse.urlencode({'email': member.email, 'sig': sig})
+
+ template_args = {
+ 'name': member.first_name.strip() + ' ' + member.last_name.strip(),
+ 'renew_url': renew_url,
+ 'baseurl': 'https://' + settings.ALLOWED_HOSTS[0]
+ }
+
+ content_html = premailer.Premailer(template_html.render(template_args), cssutils_logging_level=logging.ERROR).transform()
+ content_txt = template_txt.render(template_args)
+
+ emailer.send_raw_mail([member.email], '{} membership renewal'.format(settings.ORG_NAME), content_txt, content_html)
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.