now there is a working button at the login page to create a new user. User creation should work, although right now it lacks a check whether or not the user already exists.

This commit is contained in:
phear 2005-10-03 21:45:39 +00:00
parent cc76ec975b
commit a8fdc2ffad
6 changed files with 95 additions and 10 deletions

78
createaccount.py Normal file
View file

@ -0,0 +1,78 @@
import helper,psql
maxuser = 1000
def display_create_form(req,form):
"""
gets a request object and a util.FieldStorage form.
writes a HTML page containing one name and two password fields.
"""
data = """
<form method="post">
<p>Your username:<br>
<input name="username" type="text" id="text" size="20"></p>
<p>Your Password:<br>
<input name="password1" type="text" id="text" size="20"></p>
<p>Please retype your Password:<br>
<input name="password2" type="text" id="text" size="20"></p>
<input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="createaccount" value="process">
<p><input type="submit" id ="submit" value="create account"></p>
</form>
""" % helper.generate_session_id()
req.write(data)
def process_form(req,form):
"""
gets a request object and a util.FieldStorage form.
Tries to read out username, password1 and password2 from form.
If all needed data is there, create the named user and return a 'success'
page. Else fail with detailed error.
"""
try:
password1 = form["password1"]
except:
password1 = ""
try:
password2 = form["password2"]
except:
password2 = ""
try:
username = form["username"]
except:
username = ""
if (username != "") and (password1 != "") and (password2 != "") and (password1 == password2):
psql.add_webgo_user(username,password1)
req.write("User %s has been successfully created. Click the following button to login:<br>" % username)
data = """
<form method="post">
<input name="username" type="hidden" value="%s"></p>
<input name="password" type="hidden" value="%s"></p>
<input type="hidden" name="sessionid" value="%s">
<p><input type="submit" id ="submit" value="login"></p>
</form>
""" % (username,password1,helper.generate_session_id())
req.write(data)
else:
if username == "":
req.write("Please enter a username you would like to have.<br>")
if (password1 == "") or (password2 == "") or (password1 != password2):
req.write("Both given passwords have to be the same and non-empty.<br>")
display_create_form(req,form)
def main(req,form):
req.write(helper.header())
helper.debug(req,form,str(form.keys()))
try:
createvalue = form["createaccount"]
except:
createvalue = ""
if createvalue == "process":
process_form(req,form)
else:
display_create_form(req,form)
req.write(helper.footer())

View file

@ -20,7 +20,7 @@ def main(req,form):
manage the removal of game from game slots of players and
delete game from database.
"""
helper.debug(req,form,"<br>"+str(form.keys())+" sessionid in form:"+form["sessionid"]+"<br>")
helper.debug(req,form,str(form.keys())+" sessionid in form:"+form["sessionid"]+"<br>")
try:
gamename = form["game"]
except:

View file

@ -3,4 +3,7 @@
- what happens if a game is finished?
- add a description field for a goban table
- add a date-of-creation-creation field and a last-changed-field to goban table
- display game list more nicely with players and last change.
- display game list more nicely with players and last change.
- delete user if inactive for n months
- add a preferences page with a modify password and delete account button
- modify psql.add_webgo_user to check if user already exists

View file

@ -1,7 +1,6 @@
from mod_python import *
import psql,helper,login
DEBUG = 1
def display_game_creation_form(req,sessionid,username):
"""
@ -99,8 +98,7 @@ def main(req,form):
gets a request object and a util.FieldStorage form.
returns nothing.
"""
if DEBUG:
req.write(str(form.keys())+"<hr>")
req.write(str(form.keys())+"<hr>")
username = form["username"]
#TODO:check if valid session id

View file

@ -92,11 +92,15 @@ def login_form():
<form method="post">
<p>Name:<br>
<input name="username" type="text" id="text" size="20"></p>
<p>Pasword:<br>
<p>Password:<br>
<input name="password" type="text" id="text" size="20"></p>
<input type="hidden" name="sessionid" value="%s">
<p><input type="submit" id ="submit" value="login"></p>
</form>
<form method="post">
<input type="hidden" name="createaccount" value="init">
<input type="submit" id="submit" value="create account">
</form>
""" % helper.generate_session_id()
data += helper.footer()
return data

10
main.py
View file

@ -26,7 +26,6 @@ def handler(req):
#if sessionid=sesssionid and time < timeout:
# set_timeout
helper = apache.import_module("helper")
if (psql.get_user_info(username,'timeout') > int(time.time())) and (sessionid == psql.get_user_info(username,'sessionid')):
psql.set_user_timeout(username)
if "create" in form.keys():
@ -43,9 +42,12 @@ def handler(req):
login = apache.import_module("login")
login.main(req,form)
else:
#call login.py
login = apache.import_module("login")
login.main(req,form)
if "createaccount" in form.keys():
createaccount = apache.import_module("createaccount")
createaccount.main(req,form)
else:#call login.py
login = apache.import_module("login")
login.main(req,form)
return apache.OK
except: