diff --git a/dashboard/internet_nl_dashboard/views/signup.py b/dashboard/internet_nl_dashboard/views/signup.py index 11738ba3..13e664a5 100644 --- a/dashboard/internet_nl_dashboard/views/signup.py +++ b/dashboard/internet_nl_dashboard/views/signup.py @@ -1,5 +1,6 @@ import json import logging +import re from datetime import datetime, timedelta, timezone from time import sleep @@ -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__) @@ -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(",") @@ -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 + )