From b00665b30423e4818afafdec305202797638e145 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 31 Dec 2024 14:21:34 +0000 Subject: Removed Mailgun - all of it --- alphabetlearning/payments/views.py | 123 +++++-------------------------------- 1 file changed, 15 insertions(+), 108 deletions(-) (limited to 'alphabetlearning/payments/views.py') diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py index 7682c35..5a5d0df 100644 --- a/alphabetlearning/payments/views.py +++ b/alphabetlearning/payments/views.py @@ -1,4 +1,3 @@ -import requests import stripe from django.conf import settings from django.contrib.auth.decorators import login_required @@ -75,41 +74,27 @@ 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) + email = send_verification_email(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 = send_mailgun_verification(email=request.POST.get("email"), warn=True) + email = send_verification_email(email=request.POST.get("email"), warn=True) return render(request, "payments/verification_sent.html", {"email": email}) else: form = EmailVerificationForm() return render(request, "pages/home.html", {"form": form}) # Adjust as necessary -def send_mailgun_verification( - email: str, - verification_url: str = None, - warn=False, -): +def send_verification_email(email: str, verification_url: str = None, warn=False): if warn: warning_message = """ You are already subscribed to our list - no further action is required. """ - requests.post( - f"{settings.MAILGUN_API_URL}/{settings.MAILGUN_SENDER_DOMAIN}/messages", - auth=("api", settings.MAILGUN_API_KEY), - data={ - "from": f"No reply - Alphabet Learning ", - "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", - }, + send_mail( + subject="Alphabet Learning - Email Verification", + message=f"Thanks, {email} for signing up.\n\n{warning_message}\n\nBest regards,\n\nThe Alphabet Learning Team", + from_email=settings.DEFAULT_FROM_EMAIL, + recipient_list=[email], + fail_silently=False, ) else: warning_message = f""" @@ -117,94 +102,16 @@ def send_mailgun_verification( {verification_url} If you didn't request this, please ignore this email. """ - requests.post( - f"{settings.MAILGUN_API_URL}/{settings.MAILGUN_SENDER_DOMAIN}/messages", - auth=("api", settings.MAILGUN_API_KEY), - data={ - "from": f"No reply - Alphabet Learning ", - "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", - }, + send_mail( + subject="Alphabet Learning - Email Verification", + message=f"Thanks, {email} for signing up.\n\n{warning_message}\n\nBest regards,\n\nThe Alphabet Learning Team", + from_email=settings.DEFAULT_FROM_EMAIL, + recipient_list=[email], + fail_silently=False, ) return email -def process_verification_emails( - email: str, - verification_url: str = None, - warn=False, -): - if warn is False: - html_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.

- """ - 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. - """ - admin_warn = "They are not already subscribed." - else: - html_warning_message = """ -

You are already subscribed to our list - no further action is required.

- """ - warning_message = """ - You are already subscribed to our list - no further action is required. - """ - admin_warn = "They have already subscribed so have been told of this fact in their verification email. No further action required." - - # Send verification email - subject = "Alphabet Learning - Email Verification" - html_message = f""" - - -

Hi!

-

You recently requested to sign up to the Alphabet Learning contact list.

- {html_warning_message} -

Best regards,

-

The Alphabet Learning Team

- - - """ - message = f""" - Hi!, - - You recently requested to sign up to the Alphabet Learning contact list. - - {warning_message} - - Best regards, - The Alphabet Learning Team - """ - send_mail( - subject, - message, - settings.DEFAULT_FROM_EMAIL, - [email], - fail_silently=False, - html_message=html_message, - ) - admin_message = f""" - Joanna/Matthew, - - {email} has just signed up to the Alphabet Learning contact list. They are awaiting verification. - - {admin_warn} - - I will email again if they follow through with the verification. - - Best regards, - The Alphabet Learning Server - """ - mail_admins(subject, admin_message, fail_silently=False) - return email - - def verify_email(request, token): try: pending = EmailVerification.objects.get(verification_token=token, is_verified=False) -- cgit v1.2.3