diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2016-01-25 02:11:51 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2016-02-02 04:22:17 +0100 |
commit | d06e7ed6a741fc271e6443484bf6ecfeef5aca0c (patch) | |
tree | 2678e099bd70432260ac5012fd631835d54c42ab | |
parent | ca5e2f13aa205f71f9cb95fc0f05b2df8b03fc5b (diff) | |
download | web-d06e7ed6a741fc271e6443484bf6ecfeef5aca0c.tar.gz web-d06e7ed6a741fc271e6443484bf6ecfeef5aca0c.tar.bz2 web-d06e7ed6a741fc271e6443484bf6ecfeef5aca0c.zip |
Get services from config
-rw-r--r-- | accounts/__init__.py | 8 | ||||
-rw-r--r-- | accounts/account.py | 10 | ||||
-rw-r--r-- | accounts/default_settings.py | 5 | ||||
-rw-r--r-- | accounts/forms.py | 34 |
4 files changed, 31 insertions, 26 deletions
diff --git a/accounts/__init__.py b/accounts/__init__.py index e6927b0..61a344b 100644 --- a/accounts/__init__.py +++ b/accounts/__init__.py @@ -2,7 +2,7 @@ from flask import Flask, g, session from flask.ext.login import LoginManager -import account +from models import Service from utils import * from utils.sessions import EncryptedSessionInterface from utils.login import parse_userid @@ -17,7 +17,11 @@ app.config.from_object('accounts.default_settings') app.config.from_envvar('SPLINE_ACCOUNT_WEB_SETTINGS', silent=True) app.session_interface = EncryptedSessionInterface() -app.all_services = account.SERVICES #TODO: take that from our json file or so +app.all_services = list() +for (name, url) in app.config.get('SERVICES', list()): + cn = name.lower() + app.all_services.append(Service(cn, name, url)) + app.user_backend = get_backend(app.config['USER_BACKEND'], app) app.mail_backend = get_backend(app.config['MAIL_BACKEND'], app) diff --git a/accounts/account.py b/accounts/account.py deleted file mode 100644 index 72ea42d..0000000 --- a/accounts/account.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -from models import Service - -SERVICES = [ - Service('foren', 'Foren', 'https://foren.spline.inf.fu-berlin.de/'), - Service('fragen', 'Fragen', 'https://fragen.spline.inf.fu-berlin.de/'), - Service('gitlab', 'Gitlab', 'https://gitlab.spline.inf.fu-berlin.de/'), - Service('jabber', 'Jabber', 'http://jabber.spline.de/'), - Service('zettel', 'Zettel', 'https://zettel.spline.inf.fu-berlin.de/'), -] diff --git a/accounts/default_settings.py b/accounts/default_settings.py index 4fe53a6..eef0de5 100644 --- a/accounts/default_settings.py +++ b/accounts/default_settings.py @@ -25,3 +25,8 @@ PREFERRED_URL_SCHEME = 'https' USER_BACKEND = 'accounts.backend.user.dummy' MAIL_BACKEND = 'accounts.backend.mail.dummy' + +SERVICES = [ + ('Service1', 'https://service1.spline.de'), + ('Service2', 'https://service2.spline.de'), +] diff --git a/accounts/forms.py b/accounts/forms.py index bdef0ed..bbae07f 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -from account import SERVICES from flask import g, current_app, session, Markup from flask.ext.wtf import Form from flask.ext.login import current_user from wtforms import TextField, PasswordField, ValidationError, BooleanField,\ validators +from wtforms.form import FormMeta from functools import partial from utils import _username_re, _username_exclude_re, NotRegexp, url_for @@ -81,9 +81,26 @@ class LostPasswordForm(Form): raise ValidationError(u'Es gibt keinen Benutzer mit dieser Adresse.') +class SettingsMeta(FormMeta): + def __call__(cls, *args, **kwargs): + for service in current_app.all_services: + setattr(cls, 'password_%s' % service.id, PasswordField( + u'Passwort für %s' % service.name, [ + validators.Optional(), + validators.EqualTo( + 'password_confirm_%s' % service.id, + message=u'Passwörter stimmen nicht überein'), + ])) + setattr(cls, 'password_confirm_%s' % service.id, PasswordField( + u'Passwort für %s (Bestätigung)' % service.name)) + setattr(cls, 'delete_%s' % service.id, BooleanField( + u'Passwort für %s löschen' % service.name)) + return super(SettingsMeta, cls).__call__(*args, **kwargs) class SettingsForm(Form): + __metaclass__ = SettingsMeta + old_password = PasswordField('Altes Passwort') password = PasswordField('Neues Passwort', [validators.Optional(), validators.EqualTo('password_confirm', message=u'Passwörter stimmen nicht überein')]) @@ -105,8 +122,10 @@ class SettingsForm(Form): def get_servicepassword(self, service_id): return getattr(self, 'password_%s' % service_id) + def get_servicepasswordconfirm(self, service_id): return getattr(self, 'password_confirm_%s' % service_id) + def get_servicedelete(self, service_id): return getattr(self, 'delete_%s' % service_id) @@ -119,16 +138,3 @@ class AdminDisableAccountForm(Form): form.user = current_app.user_backend.get_by_uid(field.data) except current_app.user_backend.NoSuchUserError: raise ValidationError(u'Dieser Benutzername existiert nicht') - - -#TODO: find out how we can use app.all_services in that early state -for service in SERVICES: - setattr(SettingsForm, 'password_%s' % service.id, - PasswordField(u'Passwort für %s' % service.name, [ - validators.Optional(), - validators.EqualTo('password_confirm_%s' % service.id, message=u'Passwörter stimmen nicht überein'), - ])) - setattr(SettingsForm, 'password_confirm_%s' % service.id, - PasswordField(u'Passwort für %s (Bestätigung)' % service.name)) - setattr(SettingsForm, 'delete_%s' % service.id, - BooleanField(u'Passwort für %s löschen' % service.name)) |