mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +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 django import forms
|
||||||
|
|
||||||
from sso.models import ServiceAccount
|
from sso.models import ServiceAccount, Service
|
||||||
|
|
||||||
class EveAPIForm(forms.Form):
|
class EveAPIForm(forms.Form):
|
||||||
user_id = forms.CharField(max_length=10)
|
user_id = forms.CharField(max_length=10)
|
||||||
api_key = forms.CharField(max_length=100)
|
api_key = forms.CharField(max_length=100)
|
||||||
description = forms.CharField(max_length=100)
|
description = forms.CharField(max_length=100)
|
||||||
|
|
||||||
class ServiceAccountForm(forms.ModelForm):
|
class ServiceUsernameField(forms.CharField):
|
||||||
class Meta:
|
def clean(self, request, initial=None):
|
||||||
model = ServiceAccount
|
field = super(ServiceUsernameField, self).clean(request)
|
||||||
exclude = ['user', 'active']
|
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))
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ def service_add(request):
|
|||||||
acc.password = form.cleaned_data['password']
|
acc.password = form.cleaned_data['password']
|
||||||
|
|
||||||
acc.save()
|
acc.save()
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('sso.views.profile')) # Redirect after POST
|
return HttpResponseRedirect(reverse('sso.views.profile')) # Redirect after POST
|
||||||
else:
|
else:
|
||||||
form = ServiceAccountForm() # An unbound form
|
form = ServiceAccountForm() # An unbound form
|
||||||
|
|||||||
Reference in New Issue
Block a user