Browse Source

#4 added support for registration with a key and text for registration desk

pull/14/head
Rogier Neeleman 8 years ago
parent
commit
82d07d92ff
  1. 11
      nfgame.cfg-example
  2. 21
      nfgame.py
  3. 9
      templates/gotoregistration.html
  4. 2
      templates/newuser.html

11
nfgame.cfg-example

@ -5,7 +5,16 @@ TAGS = {'taghash1': 'tree', @@ -5,7 +5,16 @@ TAGS = {'taghash1': 'tree',
'taghash4': 'water tap'
}
# Key for starting as a new user.
# http://<server>/newuser/<key>
# 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!'
ADMIN_PASSWORD = 'changeme!'

21
nfgame.py

@ -17,6 +17,7 @@ app.config.update(dict( @@ -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(): @@ -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/<string:newhash>/', 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): @@ -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']

9
templates/gotoregistration.html

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
{% extends "layout.html" %}
{% block body %}
<center>
<h1>Error!</h1>
You are not registered as a player! Got to the registration desk.<br>
{{ registration }}
</center>
{% endblock %}

2
templates/newuser.html

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
{% extends "layout.html" %}
{% block body %}
<center>
<form action="{{ url_for('new_user') }}" method=post>
<form action="{{ url_for('new_user') }}{{ newhash }}/" method=post>
<dl>
<dt>We don't know you!
<dd>Choose a name:

Loading…
Cancel
Save