Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5605: only lowercase the domain portion of an email address in…

… `UserManager.create_user`.

Thanks, Leo.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12641 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 973bf6f4856ec3769398caa643ccc61dff4b19f4 1 parent 8b2662c
Jacob Kaplan-Moss authored March 01, 2010
20  django/contrib/auth/models.py
@@ -103,9 +103,25 @@ def __unicode__(self):
103 103
 
104 104
 class UserManager(models.Manager):
105 105
     def create_user(self, username, email, password=None):
106  
-        "Creates and saves a User with the given username, e-mail and password."
  106
+        """
  107
+        Creates and saves a User with the given username, e-mail and password.
  108
+        """
  109
+
107 110
         now = datetime.datetime.now()
108  
-        user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now)
  111
+        
  112
+        # Normalize the address by lowercasing the domain part of the email
  113
+        # address.
  114
+        try:
  115
+            email_name, domain_part = email.strip().split('@', 1)
  116
+        except ValueError:
  117
+            pass
  118
+        else:
  119
+            email = '@'.join([email_name, domain_part.lower()])
  120
+
  121
+        user = self.model(username=username, email=email, is_staff=False,
  122
+                         is_active=True, is_superuser=False, last_login=now,
  123
+                         date_joined=now)
  124
+
109 125
         if password:
110 126
             user.set_password(password)
111 127
         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
 """
11  docs/topics/auth.txt
@@ -293,10 +293,13 @@ Manager functions
293 293
     .. method:: models.UserManager.create_user(username, email, password=None)
294 294
 
295 295
         Creates, saves and returns a :class:`~django.contrib.auth.models.User`.
296  
-        The :attr:`~django.contrib.auth.models.User.username`,
297  
-        :attr:`~django.contrib.auth.models.User.email` and
298  
-        :attr:`~django.contrib.auth.models.User.password` are set as given, and the
299  
-        :class:`~django.contrib.auth.models.User` gets ``is_active=True``.
  296
+        
  297
+        The :attr:`~django.contrib.auth.models.User.username` and
  298
+        :attr:`~django.contrib.auth.models.User.password` are set as given. The
  299
+        domain portion of :attr:`~django.contrib.auth.models.User.email` is
  300
+        automatically convered to lowercase, and the returned
  301
+        :class:`~django.contrib.auth.models.User` object will have
  302
+        :attr:`~models.User.is_active` set to ``True``.
300 303
 
301 304
         If no password is provided,
302 305
         :meth:`~django.contrib.auth.models.User.set_unusable_password()` will

0 notes on commit 973bf6f

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