Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #5605: only lowercase the domain portion of an email ad…

…dress 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
  • Loading branch information...
commit 34a3b7b6fd288ce2e498b20506d16db84bd7c68b 1 parent ac72c8d
Jacob Kaplan-Moss authored March 01, 2010
20  django/contrib/auth/models.py
@@ -95,9 +95,25 @@ def __unicode__(self):
95 95
 
96 96
 class UserManager(models.Manager):
97 97
     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
+
99 102
         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
+
101 117
         if password:
102 118
             user.set_password(password)
103 119
         else:
9  django/contrib/auth/tests/forms.py
@@ -219,4 +219,13 @@
219 219
 >>> form.cleaned_data['email']
220 220
 u'jsmith3@example.com'
221 221
 
  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', 'tesT@EXAMple.com', 'test')
  225
+>>> user.email
  226
+'tesT@example.com'
  227
+>>> user = User.objects.create_user('test3', 'tesT', 'test')
  228
+>>> user.email
  229
+'tesT'
  230
+
222 231
 """
14  docs/topics/auth.txt
@@ -23,6 +23,9 @@ The auth system consists of:
23 23
       user.
24 24
     * Messages: A simple way to queue messages for given users.
25 25
 
  26
+.. deprecated:: 1.2
  27
+   The Messages component of the auth system will be removed in Django 1.4.
  28
+
26 29
 Installation
27 30
 ============
28 31
 
@@ -261,10 +264,13 @@ Manager functions
261 264
     .. method:: models.UserManager.create_user(username, email, password=None)
262 265
 
263 266
         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``.
268 274
 
269 275
         If no password is provided,
270 276
         :meth:`~django.contrib.auth.models.User.set_unusable_password()` will

0 notes on commit 34a3b7b

Please sign in to comment.
Something went wrong with that request. Please try again.