[snowy: 23/26] Validate username for uniqueness in RegistrationFormUniqueUser



commit 760d9a654f8a30c4926897f2034e06f5554d9029
Author: Leon Handreke <leon handreke gmail com>
Date:   Sat May 29 21:11:08 2010 +0200

    Validate username for uniqueness in RegistrationFormUniqueUser

 accounts/forms.py |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/accounts/forms.py b/accounts/forms.py
index 1f448a7..8ebd945 100644
--- a/accounts/forms.py
+++ b/accounts/forms.py
@@ -58,6 +58,14 @@ class RegistrationFormUniqueUser(RegistrationFormUniqueEmail):
         username = self.cleaned_data['username']
         if username in self.username_blacklist:
             raise forms.ValidationError(_(u'This username has been reserved.  Please choose another.'))
+
+        try:
+            user = User.objects.get(username=username)
+            if user:
+                raise forms.ValidationError(_(u'This username has already been taken. Please choose another.'))
+        except User.DoesNotExist:
+            pass
+
         return username
 
     def clean_password1(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]