forked from jonoxia/platform-game
-
Notifications
You must be signed in to change notification settings - Fork 1
/
complete-level.py
executable file
·38 lines (29 loc) · 1 KB
/
complete-level.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python
# Save user's score for completing level
# NOTE TO SELF how do we prevent people from just posting scores to this
# URL that they didn't actually earn?
from database_tables import Level, Score
from webserver_utils import verify_id
import cgi
import cgitb
import datetime
cgitb.enable()
q = cgi.FieldStorage()
levelName = q.getfirst("levelName", "")
completionTime = q.getfirst("completionTime", "")
player = verify_id()
print "Content-type: text/html"
print
if (levelName != "" and completionTime != ""):
levels = Level.selectBy(name = levelName)
if levels.count() > 0:
level = levels[0]
score = Score(level = level,
player = player,
completionTime = int(completionTime),
achievedOn = datetime.datetime.now())
print "Saved score %d for %s on %s." % (int(completionTime), player.name, level.name)
else:
print "No such level as %s" % levelName
else:
print "Required info not provided."