Author: jacob
Date: 2010-03-01 14:30:44 -0600 (Mon, 01 Mar 2010)
New Revision: 12641

Modified:
   django/trunk/django/contrib/auth/models.py
   django/trunk/django/contrib/auth/tests/forms.py
   django/trunk/docs/topics/auth.txt
Log:
Fixed #5605: only lowercase the domain portion of an email address in 
`UserManager.create_user`.

Thanks, Leo.

Modified: django/trunk/django/contrib/auth/models.py
===================================================================
--- django/trunk/django/contrib/auth/models.py  2010-03-01 20:19:53 UTC (rev 
12640)
+++ django/trunk/django/contrib/auth/models.py  2010-03-01 20:30:44 UTC (rev 
12641)
@@ -103,9 +103,25 @@
 
 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:

Modified: django/trunk/django/contrib/auth/tests/forms.py
===================================================================
--- django/trunk/django/contrib/auth/tests/forms.py     2010-03-01 20:19:53 UTC 
(rev 12640)
+++ django/trunk/django/contrib/auth/tests/forms.py     2010-03-01 20:30:44 UTC 
(rev 12641)
@@ -219,4 +219,13 @@
 >>> form.cleaned_data['email']
 u'jsmi...@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', 't...@example.com', 'test')
+>>> user.email
+'t...@example.com'
+>>> user = User.objects.create_user('test3', 'tesT', 'test')
+>>> user.email
+'tesT'
+
 """

Modified: django/trunk/docs/topics/auth.txt
===================================================================
--- django/trunk/docs/topics/auth.txt   2010-03-01 20:19:53 UTC (rev 12640)
+++ django/trunk/docs/topics/auth.txt   2010-03-01 20:30:44 UTC (rev 12641)
@@ -293,10 +293,13 @@
     .. method:: models.UserManager.create_user(username, email, password=None)
 
         Creates, saves and returns a :class:`~django.contrib.auth.models.User`.
-        The :attr:`~django.contrib.auth.models.User.username`,
-        :attr:`~django.contrib.auth.models.User.email` and
-        :attr:`~django.contrib.auth.models.User.password` are set as given, 
and the
-        :class:`~django.contrib.auth.models.User` gets ``is_active=True``.
+        
+        The :attr:`~django.contrib.auth.models.User.username` and
+        :attr:`~django.contrib.auth.models.User.password` are set as given. The
+        domain portion of :attr:`~django.contrib.auth.models.User.email` is
+        automatically convered to lowercase, and the returned
+        :class:`~django.contrib.auth.models.User` object will have
+        :attr:`~models.User.is_active` set to ``True``.
 
         If no password is provided,
         :meth:`~django.contrib.auth.models.User.set_unusable_password()` will

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to