diff options
-rw-r--r-- | alphabetlearning/payments/views.py | 123 | ||||
-rw-r--r-- | config/settings/base.py | 4 | ||||
-rw-r--r-- | config/settings/production.py | 23 |
3 files changed, 17 insertions, 133 deletions
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 <noreply@{settings.MAILGUN_SENDER_DOMAIN}>", - "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 <noreply@{settings.MAILGUN_SENDER_DOMAIN}>", - "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""" - <p>Please click the following link to verify your email address within 24 hours:</p> - <p><a href="{verification_url}">{verification_url}</a></p> - <p>If you didn't request this, please ignore this email.</p> - """ - 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 = """ - <p>You are already subscribed to our list - no further action is required.</p> - """ - 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""" - <html> - <body> - <p>Hi!</p> - <p>You recently requested to sign up to the Alphabet Learning contact list.</p> - {html_warning_message} - <p>Best regards,</p> - <p>The Alphabet Learning Team</p> - </body> - </html> - """ - 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) diff --git a/config/settings/base.py b/config/settings/base.py index 991605c..aaf88fc 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -358,10 +358,6 @@ AWS_S3_ENDPOINT_URL = env("SPACES_ENDPOINT_URL") # Your stuff... # ------------------------------------------------------------------------------ -MAILGUN_API_KEY = env("MAILGUN_API_KEY") -MAILGUN_SENDER_DOMAIN = env("MAILGUN_SENDER_DOMAIN") -MAILGUN_API_URL = env("MAILGUN_API_URL", default="https://api.eu.mailgun.net/v3") - CACHES = { "default": { "BACKEND": "django.core.cache.backends.db.DatabaseCache", diff --git a/config/settings/production.py b/config/settings/production.py index 252f882..9a267e6 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -127,21 +127,7 @@ EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", default=True) # Django Admin URL regex. ADMIN_URL = env("DJANGO_ADMIN_URL") -# Anymail -# ------------------------------------------------------------------------------ -# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail -# INSTALLED_APPS += ["anymail"] -# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend -# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference -# https://anymail.readthedocs.io/en/stable/esps/mailgun/ -# EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" -# ANYMAIL = { -# "MAILGUN_API_KEY": env("MAILGUN_API_KEY"), -# "MAILGUN_SENDER_DOMAIN": env("MAILGUN_DOMAIN"), -# "MAILGUN_API_URL": env("MAILGUN_API_URL", default="https://api.mailgun.net/v3"), -# } - -#EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" +# EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" # LOGGING # ------------------------------------------------------------------------------ @@ -233,12 +219,7 @@ LOGGING = { # Your stuff... -# My manual Mailgun stuff -MAILGUN_API_KEY = env("MAILGUN_API_KEY") -MAILGUN_SENDER_DOMAIN = env("MAILGUN_SENDER_DOMAIN") -MAILGUN_API_URL = env("MAILGUN_API_URL", default="https://api.eu.mailgun.net/v3") - USE_X_FORWARDED_HOST = True SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") RECAPTCHA_USE_SSL = True # Use HTTPS for requests -#RECAPTCHA_PROXY = {'http': 'http://127.0.0.1:5000', 'https': 'https://127.0.0.1:5000'} +# RECAPTCHA_PROXY = {'http': 'http://127.0.0.1:5000', 'https': 'https://127.0.0.1:5000'} |