summaryrefslogtreecommitdiffstats
path: root/app.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-01-22 19:06:47 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2016-01-25 01:56:06 +0100
commit1ea5dd06424a2a2fb60692513d59591187389021 (patch)
treefe8ebd20ced49d8b8f7c1d94ed0ba2c8d29f5198 /app.py
parent5fde298d4b705bd256d5510493955ca98a31acdc (diff)
downloadweb-1ea5dd06424a2a2fb60692513d59591187389021.tar.gz
web-1ea5dd06424a2a2fb60692513d59591187389021.tar.bz2
web-1ea5dd06424a2a2fb60692513d59591187389021.zip
Move admin interface into a blueprint
Diffstat (limited to 'app.py')
-rw-r--r--app.py75
1 files changed, 2 insertions, 73 deletions
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/<start>')
-@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):