Skip to content

Commit 34a3b7b

Browse files
committed
[1.1.X] Fixed #5605: only lowercase the domain portion of an email address in UserManager.create_user.
Thanks, Leo. Backport of [12641] from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12642 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent ac72c8d commit 34a3b7b

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

django/contrib/auth/models.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,25 @@ def __unicode__(self):
9595

9696
class UserManager(models.Manager):
9797
def create_user(self, username, email, password=None):
98-
"Creates and saves a User with the given username, e-mail and password."
98+
"""
99+
Creates and saves a User with the given username, e-mail and password.
100+
"""
101+
99102
now = datetime.datetime.now()
100-
user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now)
103+
104+
# Normalize the address by lowercasing the domain part of the email
105+
# address.
106+
try:
107+
email_name, domain_part = email.strip().split('@', 1)
108+
except ValueError:
109+
pass
110+
else:
111+
email = '@'.join([email_name, domain_part.lower()])
112+
113+
user = self.model(username=username, email=email, is_staff=False,
114+
is_active=True, is_superuser=False, last_login=now,
115+
date_joined=now)
116+
101117
if password:
102118
user.set_password(password)
103119
else:

django/contrib/auth/tests/forms.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,13 @@
219219
>>> form.cleaned_data['email']
220220
221221
222+
# bug #5605, preserve the case of the user name (before the @ in the email address)
223+
# when creating a user.
224+
>>> user = User.objects.create_user('test2', '[email protected]', 'test')
225+
>>> user.email
226+
227+
>>> user = User.objects.create_user('test3', 'tesT', 'test')
228+
>>> user.email
229+
'tesT'
230+
222231
"""

docs/topics/auth.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ The auth system consists of:
2323
user.
2424
* Messages: A simple way to queue messages for given users.
2525

26+
.. deprecated:: 1.2
27+
The Messages component of the auth system will be removed in Django 1.4.
28+
2629
Installation
2730
============
2831

@@ -261,10 +264,13 @@ Manager functions
261264
.. method:: models.UserManager.create_user(username, email, password=None)
262265

263266
Creates, saves and returns a :class:`~django.contrib.auth.models.User`.
264-
The :attr:`~django.contrib.auth.models.User.username`,
265-
:attr:`~django.contrib.auth.models.User.email` and
266-
:attr:`~django.contrib.auth.models.User.password` are set as given, and
267-
the :class:`~django.contrib.auth.models.User` gets ``is_active=True``.
267+
268+
The :attr:`~django.contrib.auth.models.User.username` and
269+
:attr:`~django.contrib.auth.models.User.password` are set as given. The
270+
domain portion of :attr:`~django.contrib.auth.models.User.email` is
271+
automatically convered to lowercase, and the returned
272+
:class:`~django.contrib.auth.models.User` object will have
273+
:attr:`~models.User.is_active` set to ``True``.
268274

269275
If no password is provided,
270276
:meth:`~django.contrib.auth.models.User.set_unusable_password()` will

0 commit comments

Comments
 (0)