Skip to content

Commit

Permalink
send mail to person who signs up #501
Browse files Browse the repository at this point in the history
  • Loading branch information
stitch committed Mar 19, 2024
1 parent fb25ab9 commit 2b43214
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions dashboard/internet_nl_dashboard/views/signup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import re
from datetime import datetime, timedelta, timezone
from time import sleep

Expand All @@ -11,6 +12,7 @@

from dashboard.celery import app
from dashboard.internet_nl_dashboard.logic import operation_response
from dashboard.internet_nl_dashboard.logic.mail_admin_templates import xget_template
from dashboard.internet_nl_dashboard.views import get_json_body

log = logging.getLogger(__package__)
Expand Down Expand Up @@ -41,13 +43,17 @@ def process_application(request):
return JsonResponse(operation_response(success=True, message="access_requested"))

# sending mail can take a while, so don't wait for it.
send_mail_async.s(form_data).apply_async()
send_backoffice_mail_async.s(form_data).apply_async()

# also send a mail to the requester, this is a templated mail with some parameters
# the mail is always in dutch, as we don't ask for a language
send_signup_received_mail_to_requester.s(form_data).apply_async()

return JsonResponse(operation_response(success=True, message="access_requested"))


@app.task(queue="storage", ignore_result=True)
def send_mail_async(form_data):
def send_backoffice_mail_async(form_data):
email_subject = "Access to API / dashboard requested"
json_content = json.dumps({"form_data": form_data}, indent=4)
email_addresses = config.DASHBOARD_SIGNUP_NOTIFICATION_EMAIL_ADRESSES.split(",")
Expand All @@ -71,3 +77,25 @@ def send_mail_async(form_data):
priority=models.PRIORITY.now,
html_message=email_content,
)


@app.task(queue="storage", ignore_result=True)
def send_signup_received_mail_to_requester(form_data):

# perform some validation that this looks like a valid mail address
# https://stackoverflow.com/questions/8022530/how-to-check-for-valid-email-address
if not re.fullmatch(r"[^@]+@[^@]+\.[^@]+", form_data['email']):
return

# also set some sort of rate limit in case someone smart wants to send 1000's of mails quickly.

# the backoffice team will see a mail coming in every request, so don't add those addresses here...
mail.send(
sender=config.EMAIL_NOTIFICATION_SENDER,
recipients=form_data['email'], # List of email addresses also accepted
template=xget_template(
template_name="signup_thank_you",
preferred_language="nl"
),
variable_dict=form_data
)

0 comments on commit 2b43214

Please sign in to comment.