aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-12-08 16:17:38 +0000
committerMatthew Lemon <y@yulqen.org>2024-12-08 16:17:38 +0000
commitbc557f9ea2ec520533d0e697dbab8ae1539195c4 (patch)
treeed85bb81fc7ee57e44f2e86c6020a5dac554eaf8
parent9950234b1aa07fceed0d220297d158be6a067cd2 (diff)
wip: temporarily switched to mailgun testing
- this uses mailgun sandbox credentials whilst I was setting up the domain on there.
-rw-r--r--alphabetlearning/payments/views.py60
1 files changed, 41 insertions, 19 deletions
diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py
index 6290e08..4a65b48 100644
--- a/alphabetlearning/payments/views.py
+++ b/alphabetlearning/payments/views.py
@@ -69,16 +69,15 @@ def email_signup_verification(request):
"payments:verify_email", args=[str(pending_verification.verification_token)]
)
)
- email = process_verification_emails(
- email=form.cleaned_data.get("email"),
- verification_url=verification_url,
- )
- # email = send_mailgun_verification(
- # form.cleaned_data.get("email"), verification_url, pending_verification
+ # email = process_verification_emails(
+ # email=form.cleaned_data.get("email"),
+ # verification_url=verification_url,
# )
+ email = send_mailgun_verification(form.cleaned_data.get("email"), verification_url)
return render(request, "payments/verification_sent.html", {"email": email})
else:
- email = process_verification_emails(email=request.POST.get("email"), warn=True)
+ # email = process_verification_emails(email=request.POST.get("email"), warn=True)
+ email = send_mailgun_verification(email=request.POST.get("email"), warn=True)
return render(request, "payments/verification_sent.html", {"email": email})
else:
form = EmailVerificationForm()
@@ -87,20 +86,43 @@ def email_signup_verification(request):
def send_mailgun_verification(
email: str,
- verification_url: str,
- email_verification_obj: EmailVerification = False,
+ verification_url: str = None,
warn=False,
):
- requests.post(
- "https://api.mailgun.net/v3/sandbox98fd3a1c6501446aa57a9c8b76e56e15.mailgun.org/messages",
- auth=("api", "7535a010b822cd503dc5a11670a64194-f55d7446-76d3865a"),
- data={
- "from": "Excited User <mailgun@sandbox98fd3a1c6501446aa57a9c8b76e56e15.mailgun.org>",
- "to": [email, email],
- "subject": "Hello - Test from Mailgun",
- "text": f"Thanks, {email} for signing up.\n\nTesting some Mailgun awesomeness",
- },
- )
+ if warn:
+ warning_message = """
+ You are already subscribed to our list - no further action is required.
+ """
+ requests.post(
+ "https://api.mailgun.net/v3/sandbox98fd3a1c6501446aa57a9c8b76e56e15.mailgun.org/messages",
+ auth=("api", "7535a010b822cd503dc5a11670a64194-f55d7446-76d3865a"),
+ data={
+ "from": "Excited User <mailgun@sandbox98fd3a1c6501446aa57a9c8b76e56e15.mailgun.org>",
+ "to": [
+ email,
+ ],
+ "subject": "Alphabet Learning - Email Verification",
+ "text": f"Thanks, {email} for signing up.\n\n{warning_message}\n\nBest regards,\n\nThe Alphabet Learning Team",
+ },
+ )
+ else:
+ warning_message = f"""
+ Please click the following link to verify your email address within 24 hours:
+ {verification_url}
+ If you didn't request this, please ignore this email.
+ """
+ requests.post(
+ "https://api.mailgun.net/v3/sandbox98fd3a1c6501446aa57a9c8b76e56e15.mailgun.org/messages",
+ auth=("api", "7535a010b822cd503dc5a11670a64194-f55d7446-76d3865a"),
+ data={
+ "from": "Excited User <mailgun@sandbox98fd3a1c6501446aa57a9c8b76e56e15.mailgun.org>",
+ "to": [
+ email,
+ ],
+ "subject": "Alphabet Learning - Email Verification",
+ "text": f"Thanks, {email} for signing up.\n\n{warning_message}\n\nBest regards,\n\nThe Alphabet Learning Team",
+ },
+ )
return email