Skip to content

SignUp - fix signup 500 errors, block banned users, add account tests - #2611

Merged
Didayolo merged 4 commits into
developfrom
signup_issues_and_account_tests
Nov 23, 2026
Merged

Didayolo merged 4 commits into
developfrom
signup_issues_and_account_tests

Conversation

@ihsaan-ullah

@ihsaan-ullah ihsaan-ullah commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Fix 500 on sign-up with an existing email in different capitals
  • Limit sign-up email to 200 characters
  • Handle double-submit sign-up (IntegrityError) without a 500
  • Show a resend-link/contact message when the activation email fails
  • Block banned users from login and password reset
  • Add tests for sign-up, activation, login, logout, password reset and deleted users

Upgrade instructions: convert existing email addresses

500 error in signup was caused by entering the same email already registered but with some capital letters. For example instead of writing [email protected] a user enters [email protected] or [email protected]. Now that signup converts email to lowercase, we need to run the following code once this is deployed to convert all emails to lowercase.

Activate django shell plus

docker compose exec django ./manage.py shell_plus

get count of users with capitals in email

User.objects.exclude(email__isnull=True).filter(email__regex=r'[A-Z]').count()

convert emails to lowercase

from django.db import IntegrityError, transaction
from profiles.models import User

failed_users = []

for user in User.objects.exclude(email__isnull=True):
    if user.email != user.email.lower():
        original_email = user.email
        user.email = user.email.lower()
        try:
            # Each save is undone on its own if it fails, so the loop keeps going
            with transaction.atomic():
                user.save()
        except IntegrityError:
            # Another account already has this email in lowercase, e.g. "[email protected]" when "[email protected]" exists
            failed_users.append((user.id, user.username, original_email))

for user_id, username, email in failed_users:
    print(f"Could not convert id={user_id} username={username} email={email}")

get count of users agint to verify

User.objects.exclude(email__isnull=True).filter(email__regex=r'[A-Z]').count()

Issues this PR resolves

Checklist

  • Code review by me
  • Hand tested by me
  • I'm proud of my work
  • Code review by reviewer
  • Hand tested by reviewer
  • CircleCi tests are passing
  • Ready to merge

@ihsaan-ullah ihsaan-ullah linked an issue Oct 3, 2026 that may be closed by this pull request
@ihsaan-ullah ihsaan-ullah changed the title Fix sign-up 500 errors, block banned users, add account tests SignUp - fix signup 500 errors, block banned users, add account tests Oct 4, 2026
@ihsaan-ullah
ihsaan-ullah force-pushed the signup_issues_and_account_tests branch from 7c6348d to 979113d Compare October 20, 2026 06:26
@ObadaS
ObadaS force-pushed the signup_issues_and_account_tests branch from a294b86 to 0f06b5b Compare October 20, 2026 11:59
@ihsaan-ullah
ihsaan-ullah force-pushed the signup_issues_and_account_tests branch from 0f06b5b to a81ce80 Compare October 21, 2026 08:37
@ihsaan-ullah
ihsaan-ullah force-pushed the signup_issues_and_account_tests branch from a81ce80 to 9d20c3b Compare November 9, 2026 12:52
@Didayolo
Didayolo force-pushed the signup_issues_and_account_tests branch from 9d20c3b to f171b5d Compare November 13, 2026 00:59
@Didayolo

Copy link
Copy Markdown
Member

Some feedback here:

The email-lowercasing script can crash halfway.
User.email is unique=True. If two existing accounts differ only by case ([email protected] and [email protected], possible from before signup started lowercasing), user.save() will raise IntegrityError on the second one.
So the table may end up half-converted.

@ihsaan-ullah

Copy link
Copy Markdown
Collaborator Author

Some feedback here:

The email-lowercasing script can crash halfway. User.email is unique=True. If two existing accounts differ only by case ([email protected] and [email protected], possible from before signup started lowercasing), user.save() will raise IntegrityError on the second one. So the table may end up half-converted.

Nice catch. We can use the code below to catch the ones that cannot be converted and decide about theme later.

from django.db import IntegrityError, transaction
from profiles.models import User

failed_users = []

for user in User.objects.exclude(email__isnull=True):
    if user.email != user.email.lower():
        original_email = user.email
        user.email = user.email.lower()
        try:
            # Each save is undone on its own if it fails, so the loop keeps going
            with transaction.atomic():
                user.save()
        except IntegrityError:
            # Another account already has this email in lowercase, e.g. "[email protected]" when "[email protected]" exists
            failed_users.append((user.id, user.username, original_email))

for user_id, username, email in failed_users:
    print(f"Could not convert id={user_id} username={username} email={email}")

We can still use this code below to get the count before and after to see how many are converted and how many are left

User.objects.exclude(email__isnull=True).filter(email__regex=r'[A-Z]').count()

@ihsaan-ullah
ihsaan-ullah force-pushed the signup_issues_and_account_tests branch from a69e709 to 39827dd Compare November 13, 2026 20:48
@Didayolo Didayolo self-assigned this Nov 23, 2026
@Didayolo
Didayolo self-requested a review November 23, 2026 12:18
@Didayolo Didayolo mentioned this pull request Nov 23, 2026
3 of 7 tasks
@Didayolo
Didayolo force-pushed the signup_issues_and_account_tests branch from 39827dd to 70e24f0 Compare November 23, 2026 12:39
@Didayolo
Didayolo merged commit 9d76d65 into develop Nov 23, 2026
3 checks passed
@Didayolo
Didayolo deleted the signup_issues_and_account_tests branch November 23, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to sign up

2 participants