2009-09-29 15:36:25 -06:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
import cgitb; cgitb.enable()
|
|
|
|
import cgi
|
|
|
|
import fcntl
|
|
|
|
import string
|
2009-10-05 13:33:20 -06:00
|
|
|
from . import teams
|
|
|
|
from . import config
|
2009-09-29 15:36:25 -06:00
|
|
|
|
2009-10-07 10:38:30 -06:00
|
|
|
def head(title):
|
|
|
|
return '''<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
|
|
<head>
|
|
|
|
<title>Team Registration</title>
|
|
|
|
<link rel="stylesheet" href="%s" type="text/css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>%s</h1>
|
|
|
|
''' % (config.css, title)
|
|
|
|
|
|
|
|
def foot():
|
|
|
|
return '''</body></html>'''
|
|
|
|
|
2009-09-29 15:36:25 -06:00
|
|
|
def main():
|
|
|
|
print('Content-type: text/html')
|
|
|
|
print()
|
|
|
|
|
|
|
|
f = cgi.FieldStorage()
|
|
|
|
|
|
|
|
team = f.getfirst('team', '')
|
|
|
|
pw = f.getfirst('pw')
|
|
|
|
confirm_pw = f.getfirst('confirm_pw')
|
|
|
|
|
2009-10-07 15:16:15 -06:00
|
|
|
html = string.Template(config.start_html('Team Registration') +
|
2009-10-07 10:38:30 -06:00
|
|
|
('''
|
2009-10-01 18:33:21 -06:00
|
|
|
<p>
|
|
|
|
Pick a short team name: you'll be typing it a lot.
|
|
|
|
</p>
|
|
|
|
|
2009-09-29 15:36:25 -06:00
|
|
|
<form method="post" action="%s">
|
|
|
|
<fieldset>
|
2009-09-30 13:58:16 -06:00
|
|
|
<legend>Registration information:</legend>
|
|
|
|
|
|
|
|
<label>Team Name:</label>
|
2009-09-29 15:36:25 -06:00
|
|
|
<input type="text" name="team" />
|
|
|
|
<span class="error">$team_error</span><br />
|
|
|
|
|
|
|
|
<label>Password:</label>
|
|
|
|
<input type="password" name="pw" />
|
|
|
|
<br />
|
|
|
|
|
|
|
|
<label>Confirm Password:</label>
|
|
|
|
<input type="password" name="confirm_pw" />
|
|
|
|
<span class="error">$pw_match_error</span><br />
|
|
|
|
|
|
|
|
<input type="submit" value="Register" />
|
|
|
|
</fieldset>
|
2009-10-07 10:38:30 -06:00
|
|
|
</form>''' % config.url('register.cgi')) +
|
2009-10-07 15:16:15 -06:00
|
|
|
config.end_html())
|
2009-09-29 15:36:25 -06:00
|
|
|
|
|
|
|
if not (team and pw and confirm_pw): # If we're starting from the beginning?
|
|
|
|
html = html.substitute(team_error='',
|
|
|
|
pw_match_error='')
|
|
|
|
elif teams.exists(team):
|
|
|
|
html = html.substitute(team_error='Team team already taken',
|
|
|
|
pw_match_error='')
|
|
|
|
elif pw != confirm_pw:
|
|
|
|
html = html.substitute(team_error='',
|
|
|
|
pw_match_error='Passwords do not match')
|
|
|
|
else:
|
|
|
|
teams.add(team, pw)
|
2009-10-07 15:16:15 -06:00
|
|
|
html = (config.start_html('Team registered') +
|
2009-10-07 10:38:30 -06:00
|
|
|
('<p>Congratulations, <samp>%s</samp> is now registered. Go <a href="%s">back to the front page</a> and start playing!</p>' % (team, config.url(''))) +
|
2009-10-07 15:16:15 -06:00
|
|
|
config.end_html())
|
2009-09-29 15:36:25 -06:00
|
|
|
|
|
|
|
print(html)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|