Commit 52197fba by Po Tsui

Add TODO for duplicate email/username inconsistency

The function `create_account_with_params` calls `_do_create_account`,
which exhibits some discrepant behavior with throwing errors when handling
duplicate email and/or username.

A duplicate email raises a `ValidationError` (rather than the expected
`AccountValidationError`) from the first part of `_do_create_account`,
when errors from `form` (the `AccountCreationForm`) are raised.

A duplicate username raises the expected `AccountValidationError`, but
from a later part of `_do_create_account`. As a result, registering with
both duplicate username and email raises a `ValidationError` for email only.

The user message for username is “An account with the Public Username
'{username}' already exists.” which differs from that of email, “It
looks like {email} belongs to an existing account. Try again with a
different email." The latter is more consistent with other user messages.
parent af96ad26
...@@ -1728,6 +1728,11 @@ def _do_create_account(form, custom_form=None, site=None): ...@@ -1728,6 +1728,11 @@ def _do_create_account(form, custom_form=None, site=None):
UserAttribute.set_user_attribute(user, 'created_on_site', site.domain) UserAttribute.set_user_attribute(user, 'created_on_site', site.domain)
except IntegrityError: except IntegrityError:
# Figure out the cause of the integrity error # Figure out the cause of the integrity error
# TODO duplicate email is already handled by form.errors above as a ValidationError.
# The checks for duplicate email/username should occur in the same place with an
# AccountValidationError and a consistent user message returned (i.e. both should
# return "It looks like {username} belongs to an existing account. Try again with a
# different username.")
if len(User.objects.filter(username=user.username)) > 0: if len(User.objects.filter(username=user.username)) > 0:
raise AccountValidationError( raise AccountValidationError(
_("An account with the Public Username '{username}' already exists.").format(username=user.username), _("An account with the Public Username '{username}' already exists.").format(username=user.username),
...@@ -1794,6 +1799,14 @@ def create_account_with_params(request, params): ...@@ -1794,6 +1799,14 @@ def create_account_with_params(request, params):
* The user-facing text is rather unfriendly (e.g. "Username must be a * The user-facing text is rather unfriendly (e.g. "Username must be a
minimum of two characters long" rather than "Please use a username of minimum of two characters long" rather than "Please use a username of
at least two characters"). at least two characters").
* Duplicate email raises a ValidationError (rather than the expected
AccountValidationError). Duplicate username returns an inconsistent
user message (i.e. "An account with the Public Username '{username}'
already exists." rather than "It looks like {username} belongs to an
existing account. Try again with a different username.") The two checks
occur at different places in the code; as a result, registering with
both a duplicate username and email raises only a ValidationError for
email only.
""" """
# Copy params so we can modify it; we can't just do dict(params) because if # Copy params so we can modify it; we can't just do dict(params) because if
# params is request.POST, that results in a dict containing lists of values # params is request.POST, that results in a dict containing lists of values
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment