From 004fe1d6c8f0b74d0e36353f5d1428a39683ca28 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sat, 3 Apr 2010 20:55:56 +0100 Subject: [PATCH] Optional setting to disable the auto password generation for Service Accounts --- settings.py | 3 +++ sso/forms.py | 7 +++++++ sso/views.py | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/settings.py b/settings.py index ee86694..3ef8565 100644 --- a/settings.py +++ b/settings.py @@ -85,6 +85,9 @@ INSTALLED_APPS = ( # Disable the service API, used for data imports DISABLE_SERVICES = False +# Services API generates a new password for the user +GENERATE_SERVICE_PASSWORD = False + AUTH_PROFILE_MODULE = 'sso.SSOUser' LOGIN_REDIRECT_URL = "/profile" LOGIN_URL = "/login" diff --git a/sso/forms.py b/sso/forms.py index eaac5a4..5130361 100644 --- a/sso/forms.py +++ b/sso/forms.py @@ -3,6 +3,7 @@ import re from django import forms from django.contrib.auth.models import User +import settings from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter from sso.models import ServiceAccount, Service from reddit.models import RedditAccount @@ -36,6 +37,12 @@ def UserServiceAccountForm(user): character = forms.ModelChoiceField(queryset=chars, 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): 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'])) diff --git a/sso/views.py b/sso/views.py index 83cc644..96956ca 100644 --- a/sso/views.py +++ b/sso/views.py @@ -124,7 +124,10 @@ def service_add(request): acc.user = request.user acc.service = form.cleaned_data['service'] 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: acc.save()