registration_backend/forms: if username is part of the registration, check its uniqueness
This commit is contained in:
parent
0aa54d1af7
commit
3237a93d40
|
@ -69,6 +69,10 @@ class RegistrationForm(Form):
|
|||
[data['email']], fail_silently=True)
|
||||
|
||||
class RegistrationCompletionForm(forms.UserAttributeFormMixin, Form):
|
||||
error_messages = {
|
||||
'duplicate_username': _("A user with that username already exists."),
|
||||
}
|
||||
|
||||
error_css_class = 'form-field-error'
|
||||
required_css_class = 'form-field-required'
|
||||
|
||||
|
@ -128,6 +132,18 @@ class RegistrationCompletionForm(forms.UserAttributeFormMixin, Form):
|
|||
|
||||
self.fields = new_fields
|
||||
|
||||
def clean_username(self):
|
||||
username = self.cleaned_data['username']
|
||||
User = compat.get_user_model()
|
||||
try:
|
||||
User._default_manager.get(username=username)
|
||||
except User.DoesNoExist:
|
||||
return username
|
||||
raise ValidationError(
|
||||
self.error_messages['duplicate_username'],
|
||||
code='duplicate_username',
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
"""
|
||||
Verifiy that the values entered into the two password fields
|
||||
|
|
Loading…
Reference in New Issue