diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/auth/models.py | 20 | ||||
| -rw-r--r-- | django/contrib/auth/tests/forms.py | 9 |
2 files changed, 27 insertions, 2 deletions
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 0be8875412..681cf1422a 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -103,9 +103,25 @@ class Group(models.Model): class UserManager(models.Manager): def create_user(self, username, email, password=None): - "Creates and saves a User with the given username, e-mail and password." + """ + Creates and saves a User with the given username, e-mail and password. + """ + now = datetime.datetime.now() - user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now) + + # Normalize the address by lowercasing the domain part of the email + # address. + try: + email_name, domain_part = email.strip().split('@', 1) + except ValueError: + pass + else: + email = '@'.join([email_name, domain_part.lower()]) + + user = self.model(username=username, email=email, is_staff=False, + is_active=True, is_superuser=False, last_login=now, + date_joined=now) + if password: user.set_password(password) else: diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py index a6ab2c448b..05a8a3f094 100644 --- a/django/contrib/auth/tests/forms.py +++ b/django/contrib/auth/tests/forms.py @@ -219,4 +219,13 @@ True >>> form.cleaned_data['email'] u'jsmith3@example.com' +# bug #5605, preserve the case of the user name (before the @ in the email address) +# when creating a user. +>>> user = User.objects.create_user('test2', 'tesT@EXAMple.com', 'test') +>>> user.email +'tesT@example.com' +>>> user = User.objects.create_user('test3', 'tesT', 'test') +>>> user.email +'tesT' + """ |
