mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Optional setting to disable the auto password generation for Service Accounts
This commit is contained in:
@@ -85,6 +85,9 @@ INSTALLED_APPS = (
|
|||||||
# Disable the service API, used for data imports
|
# Disable the service API, used for data imports
|
||||||
DISABLE_SERVICES = False
|
DISABLE_SERVICES = False
|
||||||
|
|
||||||
|
# Services API generates a new password for the user
|
||||||
|
GENERATE_SERVICE_PASSWORD = False
|
||||||
|
|
||||||
AUTH_PROFILE_MODULE = 'sso.SSOUser'
|
AUTH_PROFILE_MODULE = 'sso.SSOUser'
|
||||||
LOGIN_REDIRECT_URL = "/profile"
|
LOGIN_REDIRECT_URL = "/profile"
|
||||||
LOGIN_URL = "/login"
|
LOGIN_URL = "/login"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import re
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
import settings
|
||||||
from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter
|
from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter
|
||||||
from sso.models import ServiceAccount, Service
|
from sso.models import ServiceAccount, Service
|
||||||
from reddit.models import RedditAccount
|
from reddit.models import RedditAccount
|
||||||
@@ -36,6 +37,12 @@ def UserServiceAccountForm(user):
|
|||||||
character = forms.ModelChoiceField(queryset=chars, required=True, empty_label=None)
|
character = forms.ModelChoiceField(queryset=chars, required=True, empty_label=None)
|
||||||
service = forms.ModelChoiceField(queryset=services, required=True, empty_label=None)
|
service = forms.ModelChoiceField(queryset=services, required=True, empty_label=None)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(ServiceAccountForm, self).__init__(*args, **kwargs)
|
||||||
|
if not settings.GENERATE_SERVICE_PASSWORD:
|
||||||
|
self.password = forms.CharField(widget=forms.PasswordInput, label="Password" )
|
||||||
|
self.fields['password'] = self.password
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if not self.cleaned_data['character'].corporation.group in self.cleaned_data['service'].groups.all():
|
if not self.cleaned_data['character'].corporation.group in self.cleaned_data['service'].groups.all():
|
||||||
raise forms.ValidationError("%s is not in a corporation allowed to access %s" % (self.cleaned_data['character'].name, self.cleaned_data['service']))
|
raise forms.ValidationError("%s is not in a corporation allowed to access %s" % (self.cleaned_data['character'].name, self.cleaned_data['service']))
|
||||||
|
|||||||
@@ -124,7 +124,10 @@ def service_add(request):
|
|||||||
acc.user = request.user
|
acc.user = request.user
|
||||||
acc.service = form.cleaned_data['service']
|
acc.service = form.cleaned_data['service']
|
||||||
acc.character = form.cleaned_data['character']
|
acc.character = form.cleaned_data['character']
|
||||||
acc.password = hashlib.sha1('%s%s%s' % (form.cleaned_data['character'].name, settings.SECRET_KEY, random.randint(0, 2147483647))).hexdigest()
|
if settings.GENERATE_SERVICE_PASSWORD:
|
||||||
|
acc.password = hashlib.sha1('%s%s%s' % (form.cleaned_data['character'].name, settings.SECRET_KEY, random.randint(0, 2147483647))).hexdigest()
|
||||||
|
else:
|
||||||
|
acc.password = form.cleaned_data['password']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
acc.save()
|
acc.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user