Optional setting to disable the auto password generation for Service Accounts

This commit is contained in:
2010-04-03 20:55:56 +01:00
parent 3854aca02d
commit 004fe1d6c8
3 changed files with 14 additions and 1 deletions

View File

@@ -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"

View File

@@ -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']))

View File

@@ -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()