Commits

offline committed 759148b

validation function added to final step of openid registration

Comments (0)

Files changed (1)

openauth/forms.py

 from openauth.fields import LoginField, PasswordField
 
 
-
 class RegistrationForm(forms.Form):
     """
     Basic registration form. 
 class OpenIDRegistrationForm(forms.Form):
     login = forms.CharField()
 
+    def clean_login(self):
+        login = self.cleaned_data['login']
+        if openauth.settings.UNIQUE_USERNAME and get_object_or_None(User, username=login):
+            raise forms.ValidationError("This username already taken");
+        return login
+
     def save(self, openid_url):
         user = User.objects.create(username=self.cleaned_data['login'])
         if openauth.settings.OPENID_ACTIVATION_REQUIRED:
         return user
 
 
-
 class NewPasswordForm(forms.Form):
     """
     Form for changing user's password.
     """
-
     password = PasswordField(label=_(u'Password'))
     password_confirmation = PasswordField(label=_(u'Password (confirmation)'))
 
-
-
     def clean_password_confirmation(self):
         pass1 = self.cleaned_data['password']
         pass2 = self.cleaned_data['password_confirmation']
         else:
             return pass1
 
-
     def save(self, user):
         user.set_password(self.cleaned_data['password'])
         user.save()
     """
     Form for email chanage.
     """
-
     email = forms.EmailField(label=_(u'New email'))
 
     def save(self):
         pass
 
 
-
 class EditUserForm(forms.Form):
     def __init__(self, user, *args, **kwargs):
         self.user = user
         self.base_fields['username'] = forms.CharField(max_length=254, initial=user.username)
         super(EditUserForm, self).__init__(*args, **kwargs)
 
-
-
     def save(self):
         self.user.username = self.cleaned_data['username']
         self.user.save()