summaryrefslogtreecommitdiff
path: root/django/contrib/auth/forms.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-04-22 21:17:42 +0200
committerClaude Paroz <claude@2xlibre.net>2016-05-16 19:38:02 +0200
commit9935f97cd203bdcc722bc3d4e96858e221d96ff8 (patch)
treebdc45bf056fc8ab8ff8bfeadf403d215aee699fb /django/contrib/auth/forms.py
parent526575c64150e10dd8666d1ed3f86eedd00df2ed (diff)
Refs #21379 -- Normalized unicode username inputs
Diffstat (limited to 'django/contrib/auth/forms.py')
-rw-r--r--django/contrib/auth/forms.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index 692cdb5dab..f279f5e893 100644
--- a/django/contrib/auth/forms.py
+++ b/django/contrib/auth/forms.py
@@ -1,5 +1,7 @@
from __future__ import unicode_literals
+import unicodedata
+
from django import forms
from django.contrib.auth import (
authenticate, get_user_model, password_validation,
@@ -60,6 +62,11 @@ class ReadOnlyPasswordHashField(forms.Field):
return False
+class UsernameField(forms.CharField):
+ def to_python(self, value):
+ return unicodedata.normalize('NFKC', super(UsernameField, self).to_python(value))
+
+
class UserCreationForm(forms.ModelForm):
"""
A form that creates a user, with no privileges, from the given username and
@@ -83,6 +90,7 @@ class UserCreationForm(forms.ModelForm):
class Meta:
model = User
fields = ("username",)
+ field_classes = {'username': UsernameField}
def __init__(self, *args, **kwargs):
super(UserCreationForm, self).__init__(*args, **kwargs)
@@ -121,6 +129,7 @@ class UserChangeForm(forms.ModelForm):
class Meta:
model = User
fields = '__all__'
+ field_classes = {'username': UsernameField}
def __init__(self, *args, **kwargs):
super(UserChangeForm, self).__init__(*args, **kwargs)
@@ -140,7 +149,7 @@ class AuthenticationForm(forms.Form):
Base class for authenticating users. Extend this to get a form that accepts
username/password logins.
"""
- username = forms.CharField(
+ username = UsernameField(
max_length=254,
widget=forms.TextInput(attrs={'autofocus': ''}),
)