From 82d07d92ff7d259787878c3cb83003420fe38362 Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Thu, 29 Jun 2017 13:18:58 +0200 Subject: [PATCH] #4 added support for registration with a key and text for registration desk --- nfgame.cfg-example | 11 ++++++++++- nfgame.py | 21 ++++++++++++++++----- templates/gotoregistration.html | 9 +++++++++ templates/newuser.html | 2 +- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 templates/gotoregistration.html diff --git a/nfgame.cfg-example b/nfgame.cfg-example index ac68412..d114963 100644 --- a/nfgame.cfg-example +++ b/nfgame.cfg-example @@ -5,7 +5,16 @@ TAGS = {'taghash1': 'tree', 'taghash4': 'water tap' } +# Key for starting as a new user. +# http:///newuser/ +# If not used, please use 'None'. +# START_KEY = 'secretstartkey' +START_KEY = 'None + +# HTML text for the registration page: +REGISTRATION_DESK = 'You can find the registration desk in the center.' + # For storing the cookie information to the client SECRET_KEY = 'Very secret key!' -ADMIN_PASSWORD = 'changeme!' \ No newline at end of file +ADMIN_PASSWORD = 'changeme!' diff --git a/nfgame.py b/nfgame.py index e1ee694..d475af6 100644 --- a/nfgame.py +++ b/nfgame.py @@ -17,6 +17,7 @@ app.config.update(dict( 'taghash3': 'tagname3', 'taghash4': 'tagname4' }, + START_KEY = 'None', SECRET_KEY = 'Very secret key!', ADMIN_PASSWORD = 'changeme!' )) @@ -79,11 +80,17 @@ def index(): return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user) -@app.route('/newuser', methods=['GET', 'POST']) -def new_user(): +@app.route('/newuser/', methods=['GET', 'POST']) +@app.route('/newuser//', methods=['GET', 'POST']) +def new_user(newhash='None'): + """Check if there is a key to the new user""" + if not app.config['START_KEY'] == 'None': + if not newhash == app.config['START_KEY']: + return redirect(url_for('index')) + """If it's a GET request, no new user should be made""" if request.method == 'GET': - return render_template('newuser.html') + return render_template('newuser.html', newhash=newhash) """Now we got a POST request""" db = get_db() @@ -106,8 +113,12 @@ def tag_found(taghash): session.pop('tag', None) if not 'id' in session: - session['tag'] = taghash - return redirect(url_for('new_user')) + '''If a user does not require central registration show new user form''' + if app.config['START_KEY'] == 'None': + session['tag'] = taghash + return redirect(url_for('new_user')) + else: + return render_template('gotoregistration.html', registration=app.config['REGISTRATION_DESK'], color='#FF9999') tags = app.config['TAGS'] diff --git a/templates/gotoregistration.html b/templates/gotoregistration.html new file mode 100644 index 0000000..6785fff --- /dev/null +++ b/templates/gotoregistration.html @@ -0,0 +1,9 @@ +{% extends "layout.html" %} +{% block body %} +
+

Error!

+ You are not registered as a player! Got to the registration desk.
+ {{ registration }} +
+{% endblock %} + diff --git a/templates/newuser.html b/templates/newuser.html index 7b56388..7d0f12c 100644 --- a/templates/newuser.html +++ b/templates/newuser.html @@ -1,7 +1,7 @@ {% extends "layout.html" %} {% block body %}
-
+
We don't know you!
Choose a name: