Skip to content

Disallow @ symbol in usernames#717

Open
Copilot wants to merge 3 commits intomasterfrom
copilot/disallow-at-symbol-in-usernames
Open

Disallow @ symbol in usernames#717
Copilot wants to merge 3 commits intomasterfrom
copilot/disallow-at-symbol-in-usernames

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

Usernames containing @ could be confused with email addresses or @-mentions. This adds validation to reject them at both registration and username-change. Existing users with @ in their usernames are unaffected.

Changes

  • auctions/validators.py (new) — validate_username_no_at_symbol validator and a USERNAME_VALIDATORS list combining Django's default username validators with the new one
  • settings.pyACCOUNT_USERNAME_VALIDATORS set to "auctions.validators.USERNAME_VALIDATORS", so allauth's adapter enforces the restriction across all signup flows natively
  • ChangeUsernameForm.clean_username — delegates to the shared validate_username_no_at_symbol validator (this form is a plain Django ModelForm, not part of allauth)
  • TestsChangeUsernameFormTest (form-level) and CustomSignupFormTest (verifies allauth adapter rejects @ usernames via the configured validators)
Original prompt

This section details on the original issue you should resolve

<issue_title>disallow @ symbol in usernames</issue_title>
<issue_description>For new users and for name changes of existing users, don't allow the @ symbol in the username field.</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: iragm <71519690+iragm@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix disallowance of @ symbol in usernames Disallow @ symbol in usernames Mar 13, 2026
Copilot AI requested a review from iragm March 13, 2026 12:47
@iragm
Copy link
Owner

iragm commented Mar 13, 2026

@copilot is there a built in way that django-allauth handles this and would that be cleaner? We have many users with @ in their ueranmes already

…rnames

Co-authored-by: iragm <71519690+iragm@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot is there a built in way that django-allauth handles this and would that be cleaner? We have many users with @ in their ueranmes already

Yes — allauth provides ACCOUNT_USERNAME_VALIDATORS exactly for this. Switched to that approach in 8dab91a.

The change creates auctions/validators.py with a validate_username_no_at_symbol function and a USERNAME_VALIDATORS list (Django's default validators + the new one), then sets ACCOUNT_USERNAME_VALIDATORS = "auctions.validators.USERNAME_VALIDATORS" in settings. Allauth's adapter calls this list on every signup/username flow automatically, so CustomSignupForm no longer needs its own clean_username. The ChangeUsernameForm (which is a plain Django ModelForm, not an allauth form) still has its own clean_username but now delegates to the shared validator.

Existing users with @ in their usernames are unaffected — this only validates new usernames on signup and on the username-change form.

@iragm iragm marked this pull request as ready for review March 13, 2026 13:12
Copilot AI review requested due to automatic review settings March 13, 2026 13:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a consistent username validation rule across django-allauth signup and the site’s username change form by disallowing @ in usernames, avoiding confusion with email-based login.

Changes:

  • Configure django-allauth to use a shared username validator list via ACCOUNT_USERNAME_VALIDATORS.
  • Introduce a reusable validate_username_no_at_symbol validator (and a USERNAME_VALIDATORS bundle).
  • Add form-level validation + tests covering both the change-username flow and allauth adapter behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
fishauctions/settings.py Wires allauth username validation to the project’s validator list.
auctions/validators.py Adds the @-blocking username validator and exported USERNAME_VALIDATORS.
auctions/forms.py Enforces the same rule in ChangeUsernameForm.clean_username().
auctions/tests.py Adds regression tests for both form validation and allauth adapter validation.

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.

disallow @ symbol in usernames

3 participants