From 4b21e3889e8337fa5bc9e58cdfc61a9f2019adc9 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 3 Dec 2024 17:27:18 +0000 Subject: Better handling of email verification --- alphabetlearning/payments/admin.py | 4 ++-- ...rename_pendingemailverification_emailverification.py | 17 +++++++++++++++++ alphabetlearning/payments/models.py | 5 ++++- alphabetlearning/payments/views.py | 8 ++++---- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 alphabetlearning/payments/migrations/0012_rename_pendingemailverification_emailverification.py (limited to 'alphabetlearning/payments') 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') -- cgit v1.2.3