From 1ea5dd06424a2a2fb60692513d59591187389021 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 22 Jan 2016 19:06:47 +0100 Subject: Move admin interface into a blueprint --- app.py | 75 ++---------------------------------------------------------------- 1 file changed, 2 insertions(+), 73 deletions(-) (limited to 'app.py') diff --git a/app.py b/app.py index c29054c..844ea86 100644 --- a/app.py +++ b/app.py @@ -8,10 +8,10 @@ from flask import flash, Flask, g, redirect, request, session from utils import * from uuid import uuid4 - - +from views import admin app = Flask(__name__) +app.register_blueprint(admin.bp, url_prefix='/admin') app.config.from_object('default_settings') if 'SPLINE_ACCOUNT_WEB_SETTINGS' in os.environ: app.config.from_envvar('SPLINE_ACCOUNT_WEB_SETTINGS') @@ -280,77 +280,6 @@ def about(): return {} -@app.route('/admin') -@templated('admin_index.html') -def admin(): - return {} - - -@app.route('/admin/create_account', methods=['GET', 'POST']) -@templated('admin_create_account.html') -@admin_required -def admin_create_account(): - form = AdminCreateAccountForm() - if request.method == 'POST' and form.validate(): - send_register_confirmation_mail(form.username.data, form.mail.data) - - flash(u'Mail versandt.', 'success') - return redirect(url_for('admin')) - return {'form': form} - -@app.route('/admin/view_blacklist') -@app.route('/admin/view_blacklist/') -@templated('admin_view_blacklist.html') -@admin_required -def admin_view_blacklist(start=''): - entries = app.username_blacklist - if start: - entries = [e for e in entries if e.startswith(start)] - - next_letters = set(e[len(start)] for e in entries if len(e) > len(start)) - - return { - 'entries': entries, - 'start': start, - 'next_letters': next_letters, - } - - -@app.route('/admin/disable_account', methods=['GET', 'POST']) -@templated('admin_disable_account.html') -@admin_required -def admin_disable_account(): - form = AdminDisableAccountForm() - if 'uid' in request.args: - form = AdminDisableAccountForm(username=request.args['uid']) - if request.method == 'POST' and form.validate(): - random_pw = str(uuid4()) - form.user.change_password(random_pw) - for service in app.all_services: - form.user.reset_password(service.id) - - oldmail = form.user.attributes['mail'] - mail = app.config['DISABLED_ACCOUNT_MAILADDRESS_TEMPLATE'] % form.user.uid - form.user.change_email(mail) - - g.ldap.update(form.user, as_admin=True) - - flash(u'Passwort auf ein zufälliges und Mailadresse auf %s ' - u'gesetzt.' % mail, 'success') - - if app.config.get('MAIL_REGISTER_NOTIFY'): - send_mail( - app.config['MAIL_REGISTER_NOTIFY'], - u'[accounts] Benutzer %s deaktiviert' % form.user.uid, - 'Benutzername: %s\nE-Mail war: %s\n\ndurch: %s\n' % \ - (form.user.uid, oldmail, session['username']) - ) - - return redirect(url_for('admin')) - - return {'form': form} - - @app.errorhandler(403) @app.errorhandler(404) def errorhandler(e): -- cgit v1.2.3-1-g7c22