mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Fixes SSO forms, now doesnt error when missing a value on Service Add forms
This commit is contained in:
24
sso/forms.py
24
sso/forms.py
@@ -8,6 +8,7 @@ from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter, EVEPlayerC
|
|||||||
from sso.models import ServiceAccount, Service
|
from sso.models import ServiceAccount, Service
|
||||||
from reddit.models import RedditAccount
|
from reddit.models import RedditAccount
|
||||||
|
|
||||||
|
|
||||||
class EveAPIForm(forms.Form):
|
class EveAPIForm(forms.Form):
|
||||||
""" EVE API input form """
|
""" EVE API input form """
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ class EveAPIForm(forms.Form):
|
|||||||
else:
|
else:
|
||||||
raise forms.ValidationError("This API User ID is already registered")
|
raise forms.ValidationError("This API User ID is already registered")
|
||||||
|
|
||||||
|
|
||||||
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 """
|
||||||
|
|
||||||
@@ -49,14 +51,23 @@ def UserServiceAccountForm(user):
|
|||||||
self.fields['password'] = self.password
|
self.fields['password'] = self.password
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
|
form_data = self.cleaned_data
|
||||||
|
service = form_data.get('service')
|
||||||
|
character = form_data.get('character')
|
||||||
|
|
||||||
|
if not service or not character:
|
||||||
|
raise forms.ValidationError('Error while processing the form, please try again')
|
||||||
|
|
||||||
|
service_groups = service.groups.all()
|
||||||
|
|
||||||
# If the service's assigned groups are linked to corps, do a character/corp check
|
# If the service's assigned groups are linked to corps, do a character/corp check
|
||||||
if len(EVEPlayerCorporation.objects.filter(group__in=self.cleaned_data['service'].groups.all())):
|
if len(EVEPlayerCorporation.objects.filter(group__in=service_groups)):
|
||||||
corp_group = self.cleaned_data['character'].corporation.group
|
corp_group = character.corporation.group
|
||||||
if self.cleaned_data['character'].corporation.alliance:
|
if character.corporation.alliance:
|
||||||
alliance_group = self.cleaned_data['character'].corporation.alliance.group
|
alliance_group = character.corporation.alliance.group
|
||||||
else:
|
else:
|
||||||
alliance_group = None
|
alliance_group = None
|
||||||
service_groups = self.cleaned_data['service'].groups.all()
|
|
||||||
|
|
||||||
if not (corp_group in service_groups or alliance_group in service_groups):
|
if not (corp_group in service_groups or alliance_group in service_groups):
|
||||||
raise forms.ValidationError("%s is not in a corporation or alliance allowed to register for %s" % (self.cleaned_data['character'].name, self.cleaned_data['service']))
|
raise forms.ValidationError("%s is not in a corporation or alliance allowed to register for %s" % (self.cleaned_data['character'].name, self.cleaned_data['service']))
|
||||||
@@ -65,6 +76,7 @@ def UserServiceAccountForm(user):
|
|||||||
|
|
||||||
return ServiceAccountForm
|
return ServiceAccountForm
|
||||||
|
|
||||||
|
|
||||||
class ServiceAccountResetForm(forms.Form):
|
class ServiceAccountResetForm(forms.Form):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(ServiceAccountResetForm, self).__init__(*args, **kwargs)
|
super(ServiceAccountResetForm, self).__init__(*args, **kwargs)
|
||||||
@@ -72,6 +84,7 @@ class ServiceAccountResetForm(forms.Form):
|
|||||||
self.password = forms.CharField(widget=forms.PasswordInput, label="Password" )
|
self.password = forms.CharField(widget=forms.PasswordInput, label="Password" )
|
||||||
self.fields['password'] = self.password
|
self.fields['password'] = self.password
|
||||||
|
|
||||||
|
|
||||||
class RedditAccountForm(forms.Form):
|
class RedditAccountForm(forms.Form):
|
||||||
""" Reddit Account Form """
|
""" Reddit Account Form """
|
||||||
|
|
||||||
@@ -116,6 +129,7 @@ class UserLookupForm(forms.Form):
|
|||||||
|
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
|
|
||||||
class APIPasswordForm(forms.Form):
|
class APIPasswordForm(forms.Form):
|
||||||
|
|
||||||
password = forms.CharField(widget=forms.PasswordInput, label="Password" )
|
password = forms.CharField(widget=forms.PasswordInput, label="Password" )
|
||||||
|
|||||||
Reference in New Issue
Block a user