diff options
author | Matthew Lemon <y@yulqen.org> | 2024-12-03 17:27:18 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-12-03 17:27:18 +0000 |
commit | 4b21e3889e8337fa5bc9e58cdfc61a9f2019adc9 (patch) | |
tree | 2ecfaa0537d3fe875214934d82b31357ed769ea7 | |
parent | 3bcd728b0bd37c95865205a75ffbddfb2e086f90 (diff) |
Better handling of email verification
6 files changed, 32 insertions, 11 deletions
diff --git a/alphabetlearning/payments/admin.py b/alphabetlearning/payments/admin.py index 3980f67..156baf3 100644 --- a/alphabetlearning/payments/admin.py +++ b/alphabetlearning/payments/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin from .models import CartItem from .models import EmailSignup -from .models import PendingEmailVerification +from .models import EmailVerification from .models import Price from .models import ShoppingCart from .models import Subscription @@ -40,7 +40,7 @@ class SubscriptionAdmin(admin.ModelAdmin): # admin.site.register(Product, ProductAdmin) admin.site.register(Price) -admin.site.register(PendingEmailVerification) +admin.site.register(EmailVerification) admin.site.register(ShoppingCart, ShoppingCartAdmin) admin.site.register(CartItem) admin.site.register(Subscription, SubscriptionAdmin) diff --git a/alphabetlearning/payments/migrations/0012_rename_pendingemailverification_emailverification.py b/alphabetlearning/payments/migrations/0012_rename_pendingemailverification_emailverification.py new file mode 100644 index 0000000..770aee5 --- /dev/null +++ b/alphabetlearning/payments/migrations/0012_rename_pendingemailverification_emailverification.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.4 on 2024-12-03 17:23 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('payments', '0011_remove_pendingemailverification_first_name_and_more'), + ] + + operations = [ + migrations.RenameModel( + old_name='PendingEmailVerification', + new_name='EmailVerification', + ), + ] diff --git a/alphabetlearning/payments/models.py b/alphabetlearning/payments/models.py index 0702427..ce5c8aa 100644 --- a/alphabetlearning/payments/models.py +++ b/alphabetlearning/payments/models.py @@ -7,12 +7,15 @@ from django.db import models from alphabetlearning.resources.models import Resource -class PendingEmailVerification(models.Model): +class EmailVerification(models.Model): email = models.EmailField() verification_token = models.UUIDField(default=uuid.uuid4, editable=False) created_at = models.DateTimeField(auto_now_add=True) is_verified = models.BooleanField(default=False) + def __str__(self): + return f"Email verification for {self.email}" + class EmailSignup(models.Model): email = models.EmailField(unique=True) diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py index 9691a9f..bf4c3c9 100644 --- a/alphabetlearning/payments/views.py +++ b/alphabetlearning/payments/views.py @@ -15,7 +15,7 @@ from django.views.generic import DeleteView from django.views.generic import TemplateView from alphabetlearning.payments.models import EmailSignup -from alphabetlearning.payments.models import PendingEmailVerification +from alphabetlearning.payments.models import EmailVerification from alphabetlearning.resources.models import Resource from alphabetlearning.users.models import User @@ -59,7 +59,7 @@ def email_signup_verification(request): email = request.POST.get("email") # Create pending verification - pending_verification = PendingEmailVerification.objects.create( + pending_verification = EmailVerification.objects.create( email=email, ) @@ -97,7 +97,7 @@ def email_signup_verification(request): def verify_email(request, token): try: - pending = PendingEmailVerification.objects.get( + pending = EmailVerification.objects.get( verification_token=token, is_verified=False ) @@ -113,7 +113,7 @@ def verify_email(request, token): return render(request, 'payments/verification_success.html') - except PendingEmailVerification.DoesNotExist: + except EmailVerification.DoesNotExist: return render(request, 'payments/verification_failed.html') diff --git a/alphabetlearning/templates/payments/verification_sent.html b/alphabetlearning/templates/payments/verification_sent.html index 1de1236..063d508 100644 --- a/alphabetlearning/templates/payments/verification_sent.html +++ b/alphabetlearning/templates/payments/verification_sent.html @@ -1,6 +1,5 @@ -{% extends "base.html" %} {% load static %} {$ block content $} - +{% extends "base.html" %} {% load static %} {% block content %} <h1>Verification Email Sent</h1> <p>Please check your email at {{ email }} to complete your subscription.</p> -{$ endblock content $} +{% endblock content %} diff --git a/alphabetlearning/templates/payments/verification_success.html b/alphabetlearning/templates/payments/verification_success.html index 1f8e95a..d505fe5 100644 --- a/alphabetlearning/templates/payments/verification_success.html +++ b/alphabetlearning/templates/payments/verification_success.html @@ -1,7 +1,9 @@ -{% extends "base.html" %} {% load static %} +{% extends "base.html" %} {% load static %} {% block content %} <h1>Email Verified Successfully</h1> <p> Thank you for verifying your email. You have been added to our subscriber list. </p> + +{% endblock content %} |