mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-20 13:19:24 +00:00
Merge branch 'master' into forced-username
Conflicts: sso/forms.py
This commit is contained in:
13
sso/cron.py
13
sso/cron.py
@@ -26,23 +26,16 @@ class RemoveInvalidUsers(Job):
|
||||
|
||||
# Check each service account and delete access if they're not allowed
|
||||
for servacc in ServiceAccount.objects.filter(user=user):
|
||||
|
||||
print servacc.service.groups.all()
|
||||
print user.groups.all()
|
||||
allowedgroups = servacc.service.groups.all()
|
||||
|
||||
print set(servacc.service.groups.all()) & set(servacc.service.groups.all())
|
||||
|
||||
if not (set(servacc.service.groups.all()) & set(servacc.service.groups.all())):
|
||||
if not (set(user.groups.all()) & set(servacc.service.groups.all())):
|
||||
print "User %s is not in allowed group for %s, deleting account" % (user.username, servacc.service)
|
||||
#servacc.delete()
|
||||
servacc.delete()
|
||||
pass
|
||||
|
||||
# For users set to not active, delete all accounts
|
||||
if not user.is_active:
|
||||
print "User %s is inactive, deleting related service accounts" % user.username
|
||||
for servacc in ServiceAccount.objects.filter(user=user):
|
||||
#servacc.delete()
|
||||
servacc.delete()
|
||||
pass
|
||||
|
||||
|
||||
|
||||
10
sso/forms.py
10
sso/forms.py
@@ -37,6 +37,16 @@ def UserServiceAccountForm(user):
|
||||
character = forms.ChoiceField(chars)
|
||||
service = forms.ChoiceField(services)
|
||||
|
||||
def clean_username(self):
|
||||
field = self.cleaned_data.get('username', '')
|
||||
|
||||
# Checks that usernames consist of letters and numbers only
|
||||
if not re.match("^[A-Za-z0-9_-]*$", field):
|
||||
raise forms.ValidationError("Invalid character in username, use letters and numbers only")
|
||||
|
||||
return field
|
||||
|
||||
|
||||
def clean(self):
|
||||
if not self.cleaned_data['character'].corporation.group in self.cleaned_data['service'].groups.all():
|
||||
raise form.ValidationError("%s is not in a corporation allowed to access %s" % (self.cleaned_data['character'].name, self.cleaned_data['service'])
|
||||
|
||||
@@ -44,22 +44,23 @@ class SSOUser(models.Model):
|
||||
# Create a list of Char groups
|
||||
chargroups = []
|
||||
for eacc in EVEAccount.objects.filter(user=self.user):
|
||||
for char in eacc.characters.all():
|
||||
if char.corporation.group:
|
||||
chargroups.append(char.corporation.group)
|
||||
if eacc.api_status == 1:
|
||||
for char in eacc.characters.all():
|
||||
if char.corporation.group:
|
||||
chargroups.append(char.corporation.group)
|
||||
|
||||
# Generate the list of groups to add/remove
|
||||
delgroups = set(set(self.user.groups.all()) & set(corpgroups)) - set(chargroups)
|
||||
addgroups = set(chargroups) - set(set(self.user.groups.all()) & set(corpgroups))
|
||||
|
||||
print "Del:", delgroups
|
||||
for g in delgroups:
|
||||
self.user.groups.remove(g)
|
||||
|
||||
print "Add:", addgroups
|
||||
for g in addgroups:
|
||||
self.user.groups.add(g)
|
||||
|
||||
print "%s, Add: %s, Del: %s, Current: %s" % (self.user, addgroups, delgroups, self.user.groups.all())
|
||||
|
||||
def __str__(self):
|
||||
return self.user.__str__()
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class BaseService():
|
||||
|
||||
def add_user(self, username, password):
|
||||
""" Add a user, returns a UID for that user """
|
||||
pass
|
||||
return username
|
||||
|
||||
def check_user(self, username):
|
||||
""" Check if the username exists """
|
||||
|
||||
20
sso/views.py
20
sso/views.py
@@ -67,9 +67,7 @@ def eveapi_add(request):
|
||||
else:
|
||||
form = EveAPIForm() # An unbound form
|
||||
|
||||
return render_to_response('sso/eveapi.html', {
|
||||
'form': form,
|
||||
})
|
||||
return render_to_response('sso/eveapi.html', locals())
|
||||
|
||||
@login_required
|
||||
def eveapi_del(request, userid=0):
|
||||
@@ -113,9 +111,7 @@ def service_add(request):
|
||||
#defaults = { 'username': request.user.username, 'password': request.user.get_profile().default_service_passwd }
|
||||
form = clsform() # An unbound form
|
||||
|
||||
return render_to_response('sso/serviceaccount.html', {
|
||||
'form': form,
|
||||
})
|
||||
return render_to_response('sso/serviceaccount.html', locals())
|
||||
|
||||
@login_required
|
||||
def service_del(request, serviceid=0):
|
||||
@@ -150,9 +146,7 @@ def reddit_add(request):
|
||||
defaults = { 'username': request.user.username, }
|
||||
form = RedditAccountForm(defaults) # An unbound form
|
||||
|
||||
return render_to_response('sso/redditaccount.html', {
|
||||
'form': form,
|
||||
})
|
||||
return render_to_response('sso/redditaccount.html', locals())
|
||||
|
||||
@login_required
|
||||
def reddit_del(request, redditid=0):
|
||||
@@ -180,13 +174,9 @@ def user_view(request, user=None):
|
||||
if form.is_valid():
|
||||
user = form.cleaned_data['username']
|
||||
else:
|
||||
return render_to_response('sso/userlookup.html', {
|
||||
'form': form,
|
||||
})
|
||||
return render_to_response('sso/userlookup.html', locals())
|
||||
else:
|
||||
return render_to_response('sso/userlookup.html', {
|
||||
'form': form,
|
||||
})
|
||||
return render_to_response('sso/userlookup.html', locals())
|
||||
|
||||
is_admin = request.user.is_staff
|
||||
|
||||
|
||||
Reference in New Issue
Block a user