mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-15 07:12:16 +00:00
Move username validation down to Form clean instead of username field clean
This commit is contained in:
16
sso/forms.py
16
sso/forms.py
@@ -36,13 +36,6 @@ class ServiceUsernameField(forms.CharField):
|
|||||||
if not re.match("^[A-Za-z0-9_-]*$", username):
|
if not re.match("^[A-Za-z0-9_-]*$", username):
|
||||||
raise forms.ValidationError("Invalid character in username, use letters and numbers only")
|
raise forms.ValidationError("Invalid character in username, use letters and numbers only")
|
||||||
|
|
||||||
try:
|
|
||||||
acc = ServiceAccount.objects.get(service_uid=field)
|
|
||||||
except ServiceAccount.DoesNotExist:
|
|
||||||
return field
|
|
||||||
else:
|
|
||||||
raise forms.ValidationError("That username is already taken")
|
|
||||||
|
|
||||||
def UserServiceAccountForm(user):
|
def UserServiceAccountForm(user):
|
||||||
""" Generate a Service Account form based on the user's permissions """
|
""" Generate a Service Account form based on the user's permissions """
|
||||||
|
|
||||||
@@ -55,6 +48,15 @@ def UserServiceAccountForm(user):
|
|||||||
username = ServiceUsernameField(min_length=4,max_length=50)
|
username = ServiceUsernameField(min_length=4,max_length=50)
|
||||||
password = forms.CharField(label = u'Password',widget = forms.PasswordInput(render_value=False))
|
password = forms.CharField(label = u'Password',widget = forms.PasswordInput(render_value=False))
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
try:
|
||||||
|
acc = ServiceAccount.objects.get(service_uid=self.cleaned_data['username'],service==self.cleaned_data['service'])
|
||||||
|
except ServiceAccount.DoesNotExist:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise forms.ValidationError("That username is already taken")
|
||||||
|
|
||||||
|
|
||||||
return ServiceAccountForm
|
return ServiceAccountForm
|
||||||
|
|
||||||
class RedditAccountForm(forms.Form):
|
class RedditAccountForm(forms.Form):
|
||||||
|
|||||||
Reference in New Issue
Block a user