Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 39 lines (29 sloc) 1.026 kb
#!/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."
Jump to Line
Something went wrong with that request. Please try again.