Browse Source

#10 New users will be checked against the database before adding.

pull/14/head
Rogier Neeleman 8 years ago
parent
commit
63c95bb0d1
  1. 8
      nfgame.py
  2. 7
      templates/newuser.html

8
nfgame.py

@ -100,6 +100,14 @@ def new_user(newhash='None'):
now = datetime.now() 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") 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() db = get_db()
cur = db.execute("insert into score (username,starttime,duration) values (?, ?, ?)", [request.form['username'], time, '99:99:99']) cur = db.execute("insert into score (username,starttime,duration) values (?, ?, ?)", [request.form['username'], time, '99:99:99'])
db.commit() db.commit()

7
templates/newuser.html

@ -3,7 +3,12 @@
<center> <center>
<form action="{{ url_for('new_user') }}{{ newhash }}/" method=post> <form action="{{ url_for('new_user') }}{{ newhash }}/" method=post>
<dl> <dl>
<dt>We don't know you! <dt>
{% if msg %}
<font color="red"> {{ msg }} </font>
{% else %}
We don't know you!
{% endif %}
<dd>Choose a name: <dd>Choose a name:
<dd><input type=text name=username> <dd><input type=text name=username>
<dd><input type=submit value=Submit> <dd><input type=submit value=Submit>

Loading…
Cancel
Save