mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Allow for assigned services outside of the corp/alliance structure
This commit is contained in:
21
sso/forms.py
21
sso/forms.py
@@ -4,7 +4,7 @@ from django import forms
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter
|
from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation
|
||||||
from sso.models import ServiceAccount, Service
|
from sso.models import ServiceAccount, Service
|
||||||
from reddit.models import RedditAccount
|
from reddit.models import RedditAccount
|
||||||
|
|
||||||
@@ -51,16 +51,17 @@ def UserServiceAccountForm(user):
|
|||||||
self.fields['password'] = self.password
|
self.fields['password'] = self.password
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
# 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())):
|
||||||
|
corp_group = self.cleaned_data['character'].corporation.group
|
||||||
|
if self.cleaned_data['character'].corporation.alliance:
|
||||||
|
alliance_group = self.cleaned_data['character'].corporation.alliance.group
|
||||||
|
else:
|
||||||
|
alliance_group = None
|
||||||
|
service_groups = self.cleaned_data['service'].groups.all()
|
||||||
|
|
||||||
corp_group = self.cleaned_data['character'].corporation.group
|
if not (corp_group in service_groups or alliance_group in service_groups):
|
||||||
if self.cleaned_data['character'].corporation.alliance:
|
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']))
|
||||||
alliance_group = self.cleaned_data['character'].corporation.alliance.group
|
|
||||||
else:
|
|
||||||
alliance_group = None
|
|
||||||
service_groups = self.cleaned_data['service'].groups.all()
|
|
||||||
|
|
||||||
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']))
|
|
||||||
|
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user