1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #34438 -- Reallowed extending UserCreationForm.

Regression in 298d02a77a.
This commit is contained in:
Gary Jarrel
2023-03-27 23:26:06 +11:00
committed by Mariusz Felisiak
parent 45ecd9acca
commit fcc7dc5781
3 changed files with 46 additions and 11 deletions

View File

@@ -147,16 +147,22 @@ class BaseUserCreationForm(forms.ModelForm):
class UserCreationForm(BaseUserCreationForm):
error_messages = {
**BaseUserCreationForm.error_messages,
"unique": _("A user with that username already exists."),
}
def clean_username(self):
"""Reject usernames that differ only in case."""
username = self.cleaned_data.get("username")
if username and User.objects.filter(username__iexact=username).exists():
raise forms.ValidationError(self.error_messages["unique"], code="unique")
if (
username
and self._meta.model.objects.filter(username__iexact=username).exists()
):
self._update_errors(
ValidationError(
{
"username": self.instance.unique_error_message(
self._meta.model, ["username"]
)
}
)
)
else:
return username

View File

@@ -77,10 +77,6 @@ msgstr ""
msgid "Enter the same password as before, for verification."
msgstr ""
#: contrib/auth/forms.py:152 contrib/auth/models.py:353
msgid "A user with that username already exists."
msgstr ""
#: contrib/auth/forms.py:168
msgid ""
"Raw passwords are not stored, so there is no way to see this users "
@@ -240,6 +236,10 @@ msgstr ""
msgid "Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only."
msgstr ""
#: contrib/auth/models.py:353
msgid "A user with that username already exists."
msgstr ""
#: contrib/auth/models.py:356
msgid "first name"
msgstr ""