Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17046 -- Added a check if the username passed to User.objects.…

…create_user is empty or not. Thanks, kwadrat.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17628 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fcaf8eae14d0a7f884328bdf0238dd1e2881c681 1 parent 40b248a
Jannis Leidel authored March 02, 2012
2  django/contrib/auth/models.py
@@ -149,6 +149,8 @@ def create_user(self, username, email=None, password=None):
149 149
         Creates and saves a User with the given username, email and password.
150 150
         """
151 151
         now = timezone.now()
  152
+        if not username:
  153
+            raise ValueError('The given username must be set')
152 154
         email = UserManager.normalize_email(email)
153 155
         user = self.model(username=username, email=email,
154 156
                           is_staff=False, is_active=True, is_superuser=False,
5  django/contrib/auth/tests/models.py
@@ -91,3 +91,8 @@ def test_create_user_email_domain_normalize(self):
91 91
     def test_create_user_email_domain_normalize_with_whitespace(self):
92 92
         returned = UserManager.normalize_email('email\ with_whitespace@D.COM')
93 93
         self.assertEquals(returned, 'email\ with_whitespace@d.com')
  94
+
  95
+    def test_empty_username(self):
  96
+        self.assertRaisesMessage(ValueError,
  97
+                                 'The given username must be set',
  98
+                                  User.objects.create_user, username='')
4  docs/topics/auth.txt
@@ -280,7 +280,9 @@ Manager functions
280 280
     .. method:: models.UserManager.create_user(username, email=None, password=None)
281 281
 
282 282
         .. versionchanged:: 1.4
283  
-           The ``email`` parameter was made optional.
  283
+           The ``email`` parameter was made optional. The username
  284
+           parameter is now checked for emptiness and raises a
  285
+           :exc:`ValueError` in case of a negative result.
284 286
 
285 287
         Creates, saves and returns a :class:`~django.contrib.auth.models.User`.
286 288
 

0 notes on commit fcaf8ea

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