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 manage the removal of game from game slots of players and
delete game from database. 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: try:
gamename = form["game"] gamename = form["game"]
except: except:

View file

@ -4,3 +4,6 @@
- add a description field for a goban table - add a description field for a goban table
- add a date-of-creation-creation field and a last-changed-field to 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 * from mod_python import *
import psql,helper,login import psql,helper,login
DEBUG = 1
def display_game_creation_form(req,sessionid,username): def display_game_creation_form(req,sessionid,username):
""" """
@ -99,7 +98,6 @@ def main(req,form):
gets a request object and a util.FieldStorage form. gets a request object and a util.FieldStorage form.
returns nothing. returns nothing.
""" """
if DEBUG:
req.write(str(form.keys())+"<hr>") req.write(str(form.keys())+"<hr>")
username = form["username"] username = form["username"]

View file

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

View file

@ -26,7 +26,6 @@ def handler(req):
#if sessionid=sesssionid and time < timeout: #if sessionid=sesssionid and time < timeout:
# set_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')): if (psql.get_user_info(username,'timeout') > int(time.time())) and (sessionid == psql.get_user_info(username,'sessionid')):
psql.set_user_timeout(username) psql.set_user_timeout(username)
if "create" in form.keys(): if "create" in form.keys():
@ -43,7 +42,10 @@ def handler(req):
login = apache.import_module("login") login = apache.import_module("login")
login.main(req,form) login.main(req,form)
else: else:
#call login.py if "createaccount" in form.keys():
createaccount = apache.import_module("createaccount")
createaccount.main(req,form)
else:#call login.py
login = apache.import_module("login") login = apache.import_module("login")
login.main(req,form) login.main(req,form)