aboutsummaryrefslogtreecommitdiffstats
path: root/alphabetlearning/payments/views.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-12-04 17:11:55 +0000
committerMatthew Lemon <y@yulqen.org>2024-12-04 17:11:55 +0000
commit7cd2fd2b75bc5597e9b2a128bf61201910be6df2 (patch)
tree411c26f821129f196b2a38863a34b05e4e8388e9 /alphabetlearning/payments/views.py
parent4b21e3889e8337fa5bc9e58cdfc61a9f2019adc9 (diff)
Email verification
- Associated changes in the .env file now allow us to test the SMTP server config - Added mine and J's email ad admins - Grab env variables from the .env file in the local.py file for testing purposes - Set an expiry of 24hrs for the validation link to work - Added an HTML version of the verification email
Diffstat (limited to 'alphabetlearning/payments/views.py')
-rw-r--r--alphabetlearning/payments/views.py51
1 files changed, 43 insertions, 8 deletions
diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py
index bf4c3c9..4b6f79f 100644
--- a/alphabetlearning/payments/views.py
+++ b/alphabetlearning/payments/views.py
@@ -1,7 +1,7 @@
import stripe
from django.conf import settings
from django.contrib.auth.decorators import login_required
-from django.core.mail import send_mail
+from django.core.mail import send_mail, mail_admins
from django.http import HttpResponse
from django.http import HttpResponseBadRequest
from django.shortcuts import get_object_or_404
@@ -70,14 +70,27 @@ def email_signup_verification(request):
# Send verification email
subject = 'Alphabet Learning - Email Verification'
- message = f'''
- Hello!,
+ html_message = f'''
+ <html>
+ <body>
+ <img src="http://localhost:8000/static/images/AL_long_logo_black_grey.png" alt="Alphabet Learning Logo" style="max-width: 200px; margin-bottom: 20px;">
+ <p>Hi!</p>
+ <p>You recently requested to sign up to the Alphabet Learning contact list.</p>
+ <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>
+ <p>Best regards,</p>
+ <p>The Alphabet Learning Team</p>
+ </body>
+ </html>
+ '''
+ message = f'''
+ Hi!,
- You recently requested to sign up to the Alpabet Learning contract list.
+ You recently requested to sign up to the Alphabet Learning contact list.
- Please click the following link to verify your email address:
+ 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.
Best regards,
@@ -89,12 +102,24 @@ def email_signup_verification(request):
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.
+
+ 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 render(request, 'payments/verification_sent.html', {
'email': email
})
return render(request, "pages/home.html") # Adjust as necessary
-
def verify_email(request, token):
try:
pending = EmailVerification.objects.get(
@@ -102,6 +127,9 @@ def verify_email(request, token):
is_verified=False
)
+ if pending.is_expired:
+ return render(request, 'payments/verification_failed.html')
+
# Create the subscriber
EmailSignup.objects.create(
email=pending.email,
@@ -111,7 +139,14 @@ def verify_email(request, token):
pending.is_verified = True
pending.save()
- return render(request, 'payments/verification_success.html')
+ mail_admins(
+ subject=f'{pending.email} has just signed up to the Alphabet Learning contact list.',
+ message=f'{pending.email} has just signed up to the Alphabet Learning contact list. Their verification was successful.\n\n\n'
+ f'Best regards,\n\nThe Alphabet Learning Server',
+ fail_silently=False,
+ )
+
+ return render(request, 'payments/success_email_signup.html')
except EmailVerification.DoesNotExist:
return render(request, 'payments/verification_failed.html')