From f63b89425822db3b473ed60f205ef03e6537b2e8 Mon Sep 17 00:00:00 2001 From: CodeKevin Date: Sun, 3 May 2015 17:25:59 -0400 Subject: [PATCH] Preventing team name changes --- CTFd/admin.py | 21 ++++++++++++--------- CTFd/views.py | 12 ++++++++---- templates/admin/config.html | 5 +++++ templates/profile.html | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CTFd/admin.py b/CTFd/admin.py index 31488b8d..25e7a561 100644 --- a/CTFd/admin.py +++ b/CTFd/admin.py @@ -58,9 +58,15 @@ def init_admin(app): try: view_challenges_unregistered = bool(request.form.get('view_challenges_unregistered', None)) prevent_registration = bool(request.form.get('prevent_registration', None)) + prevent_name_change = bool(request.form.get('prevent_name_change', None)) except (ValueError, TypeError): view_challenges_unregistered = None prevent_registration = None + prevent_name_change = None + finally: + view_challenges_unregistered = set_config('view_challenges_unregistered', view_challenges_unregistered) + prevent_registration = set_config('prevent_registration', prevent_registration) + prevent_name_change = set_config('prevent_name_change', prevent_name_change) ctf_name = set_config("ctf_name", request.form.get('ctf_name', None)) mg_api_key = set_config("mg_api_key", request.form.get('mg_api_key', None)) @@ -72,16 +78,8 @@ def init_admin(app): db_end = Config.query.filter_by(key='end').first() db_end.value = end - db_view_challenges_unregistered = Config.query.filter_by(key='view_challenges_unregistered').first() - db_view_challenges_unregistered.value = view_challenges_unregistered - - db_prevent_registration = Config.query.filter_by(key='prevent_registration').first() - db_prevent_registration.value = prevent_registration - db.session.add(db_start) db.session.add(db_end) - db.session.add(db_view_challenges_unregistered) - db.session.add(db_prevent_registration) db.session.commit() return redirect('/admin/config') @@ -114,12 +112,17 @@ def init_admin(app): if not prevent_registration: set_config('prevent_registration', None) + prevent_name_change = get_config('prevent_name_change') == '1' + if not prevent_name_change: + set_config('prevent_name_change', None) + db.session.commit() db.session.close() return render_template('admin/config.html', ctf_name=ctf_name, start=start, end=end, view_challenges_unregistered=view_challenges_unregistered, - prevent_registration=prevent_registration, do_api_key=do_api_key, mg_api_key=mg_api_key) + prevent_registration=prevent_registration, do_api_key=do_api_key, mg_api_key=mg_api_key, + prevent_name_change=prevent_name_change) @app.route('/admin/pages', defaults={'route': None}, methods=['GET', 'POST']) @app.route('/admin/pages/', methods=['GET', 'POST']) diff --git a/CTFd/views.py b/CTFd/views.py index 50102498..0ad7b00c 100644 --- a/CTFd/views.py +++ b/CTFd/views.py @@ -1,5 +1,5 @@ from flask import current_app as app, render_template, render_template_string, request, redirect, abort, jsonify, json as json_mod, url_for, session -from CTFd.utils import authed, ip2long, long2ip, is_setup, validate_url +from CTFd.utils import authed, ip2long, long2ip, is_setup, validate_url, get_config from CTFd.models import db, Teams, Solves, Challenges, WrongKeys, Keys, Tags, Files, Tracking, Pages, Config from jinja2.exceptions import TemplateNotFound @@ -158,10 +158,12 @@ def init_views(app): errors.append("That doesn't look like a valid URL") if len(errors) > 0: - return render_template('profile.html', name=name, email=email, website=website, affiliation=affiliation, country=country, errors=errors) + return render_template('profile.html', name=name, email=email, website=website, + affiliation=affiliation, country=country, errors=errors) else: team = Teams.query.filter_by(id=session['id']).first() - team.name = name + if not get_config('prevent_name_change'): + team.name = name team.email = email session['username'] = name @@ -180,6 +182,8 @@ def init_views(app): website = user.website affiliation = user.affiliation country = user.country - return render_template('profile.html', name=name, email=email, website=website, affiliation=affiliation, country=country) + prevent_name_change = get_config('prevent_name_change') + return render_template('profile.html', name=name, email=email, website=website, affiliation=affiliation, + country=country, prevent_name_change=prevent_name_change) else: return redirect('/login') diff --git a/templates/admin/config.html b/templates/admin/config.html index e8951d6a..ddbbb10e 100644 --- a/templates/admin/config.html +++ b/templates/admin/config.html @@ -42,6 +42,11 @@ +
+ + +
+ diff --git a/templates/profile.html b/templates/profile.html index 1e67ed1f..9fa90a41 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -10,7 +10,7 @@ {% endfor %}
Team Name - + Email Address