diff --git a/accounts/models.py b/accounts/models.py index 5701990..afe76fd 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -48,3 +48,6 @@ class AccountConfirmChallenge(models.Model): Get verification link """ return reverse("accounts.verify", args=(self.challenge_text,)) + + def pending_url(self): + return reverse("accounts.verify.pending", args=(self.public_ref,)) diff --git a/accounts/views.py b/accounts/views.py index 9554ec0..114d176 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -134,11 +134,19 @@ def register_view(request): password=password, ) # TODO: get email from settings.py - challenge = AccountConfirmChallenge(owned_by=user) - challenge.save() - send_verification_email(request, challenge=challenge) + challenge = None - return redirect(reverse("accounts.verify.pending", args=(challenge.public_ref,))) + if not AccountConfirmChallenge.objects.filter(owned_by=user).exists(): + challenge = AccountConfirmChallenge(owned_by=user) + challenge.save() + send_verification_email(request, challenge=challenge) + else: + challenge = AccountConfirmChallenge.objects.get(owned_by=user) + + user.is_active = False + user.save() + + return redirect(challenge.pending_url()) def verification_pending_view(request, public_ref): @@ -155,7 +163,7 @@ def verification_pending_view(request, public_ref): def resend_verification_email_view(request, public_ref): challenge = get_object_or_404(AccountConfirmChallenge, public_ref=public_ref) send_verification_email(request, challenge=challenge) - return redirect(reverse("accounts.verify.pending", args=(challenge.public_ref,))) + return redirect(challenge.pending_url()) def verify_account(request, challenge):