#! /usr/bin/python import cgitb; cgitb.enable() import cgi import os import fcntl import string from ctf import teams, html def main(): f = cgi.FieldStorage() team = f.getfirst('team', '') pw = f.getfirst('pw') confirm_pw = f.getfirst('confirm_pw') tmpl = string.Template('''
Pick a short team name: you'll be typing it a lot.
''') if not (team and pw and confirm_pw): # If we're starting from the beginning? body = tmpl.substitute(team_error='', pw_match_error='') elif teams.exists(team): body = tmpl.substitute(team_error='Team team already taken', pw_match_error='') elif pw != confirm_pw: body = tmpl.substitute(team_error='', pw_match_error='Passwords do not match') else: teams.add(team, pw) body = ('Congratulations, %s is now registered. Go back to the front page and start playing!
' % cgi.escape(team)) html.serve('Team Registration', body) if __name__ == '__main__': import sys, codecs sys.stdout = codecs.getwriter('utf-8')(sys.stdout) main()