mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Added a bit of form validation
This commit is contained in:
20
sso/forms.py
20
sso/forms.py
@@ -1,14 +1,24 @@
|
||||
from django import forms
|
||||
|
||||
from sso.models import ServiceAccount
|
||||
from sso.models import ServiceAccount, Service
|
||||
|
||||
class EveAPIForm(forms.Form):
|
||||
user_id = forms.CharField(max_length=10)
|
||||
api_key = forms.CharField(max_length=100)
|
||||
description = forms.CharField(max_length=100)
|
||||
|
||||
class ServiceAccountForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = ServiceAccount
|
||||
exclude = ['user', 'active']
|
||||
class ServiceUsernameField(forms.CharField):
|
||||
def clean(self, request, initial=None):
|
||||
field = super(ServiceUsernameField, self).clean(request)
|
||||
try:
|
||||
acc = ServiceAccount.objects.get(username=field)
|
||||
except ServiceAccount.DoesNotExist:
|
||||
return field
|
||||
else:
|
||||
raise forms.ValidationError("That username is already taken")
|
||||
|
||||
class ServiceAccountForm(forms.Form):
|
||||
service = forms.ModelChoiceField(queryset=Service.objects.filter(active=1), empty_label="Select A Service... ")
|
||||
username = ServiceUsernameField(min_length=4,max_length=50)
|
||||
password = forms.CharField(label = u'Password',widget = forms.PasswordInput(render_value=False))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user