From 63c95bb0d1d9750bffc6b2a64cc7fae5395373a2 Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Sun, 2 Jul 2017 20:48:19 +0200 Subject: [PATCH] #10 New users will be checked against the database before adding. --- nfgame.py | 8 ++++++++ templates/newuser.html | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/nfgame.py b/nfgame.py index 2ecd111..3599e0d 100644 --- a/nfgame.py +++ b/nfgame.py @@ -100,6 +100,14 @@ def new_user(newhash='None'): now = datetime.now() time = datetime.strptime((str(now.year)+"-"+str(now.month)+"-"+str(now.day)+" "+str(now.hour)+":"+str(now.minute)+":"+str(now.second)), "%Y-%m-%d %H:%M:%S") + """Check for unique username""" + db = get_db() + cur = db.execute('select count(username) as count from score where username = ? COLLATE NOCASE', [request.form['username']]) + usercount = cur.fetchone() + + if not usercount['count'] == 0: + return render_template('newuser.html', newhash=newhash, msg='Username already taken!') + db = get_db() cur = db.execute("insert into score (username,starttime,duration) values (?, ?, ?)", [request.form['username'], time, '99:99:99']) db.commit() diff --git a/templates/newuser.html b/templates/newuser.html index 7d0f12c..c759ae9 100644 --- a/templates/newuser.html +++ b/templates/newuser.html @@ -3,7 +3,12 @@
-
We don't know you! +
+ {% if msg %} + {{ msg }} + {% else %} + We don't know you! + {% endif %}
Choose a name: