From 1ebdcc5c6439e0b36afd484501dbeee852f66f01 Mon Sep 17 00:00:00 2001 From: saikumarvasa100-hash Date: Mon, 24 Nov 2025 17:01:22 +0530 Subject: [PATCH] Fix: Make candidate account creation case insensitive and check for duplicate emails This addresses issue #500 by: 1. Making username comparison case-insensitive during candidate account provisioning 2. Adding duplicate email validation to prevent accounts with existing emails Fixes #500 --- hknweb/forms.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index a50a8df6..b3c81996 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -225,6 +225,19 @@ def email_to_username(email: str) -> str: "username", flat=True ) ) + + # Get existing emails + emails = [] + for row in rows: + email = row["Berkeley email"] + if email: + emails.append(email) + + existing_emails = set( + User.objects.filter(email__in=emails).values_list( + "email", flat=True + ) + ) # Setup account provisioning utils # Get candidate group to add users to @@ -241,7 +254,7 @@ def generate_password() -> str: email_information = [] for row in rows: # If username is None or already exists, skip provisioning - if (row["username"] is None) or (row["username"] in existing_usernames): + if (row["username"] is None) or (row["username"].lower() in existing_usernames) or (row["Berkeley email"] in existing_emails): continue # Generate a password