implemented logout button.

This commit is contained in:
phear 2005-10-09 22:11:29 +00:00
parent 055756dab1
commit 27307791fd
7 changed files with 40 additions and 19 deletions

View file

@ -75,4 +75,4 @@ def main(req,form):
else: else:
display_create_form(req,form) display_create_form(req,form)
req.write(helper.footer()) req.write(helper.footer(req,form))

View file

@ -2,12 +2,16 @@ from mod_python import *
import psql,helper,login import psql,helper,login
def display_game_creation_form(req,sessionid,username): def display_game_creation_form(req,form):
""" """
prints a html form with multiple drop-down lists for choosing players, prints a html form with multiple drop-down lists for choosing players,
goban size and so on. goban size and so on.
gets a mod_python request, prints to req.write. gets a mod_python request, prints to req.write.
""" """
username = form["username"]
sessionid = form["sessionid"]
data = helper.header() data = helper.header()
p1data = create_user_dropdown_list("player1",username) p1data = create_user_dropdown_list("player1",username)
p2data = create_user_dropdown_list("player2") p2data = create_user_dropdown_list("player2")
@ -29,7 +33,7 @@ def display_game_creation_form(req,sessionid,username):
data+=helper.footer() data+=helper.footer(req,form)
req.write(data) req.write(data)
def process_creation_form(req,form): def process_creation_form(req,form):
@ -112,6 +116,6 @@ def main(req,form):
if "gobansize" in form.keys(): #user already clicked on create if "gobansize" in form.keys(): #user already clicked on create
process_creation_form(req,form) process_creation_form(req,form)
else: else:
display_game_creation_form(req,sessionid,username) display_game_creation_form(req,form,)

View file

@ -163,11 +163,11 @@ def update_goban_dict_and_table(gobandict,gobanlite):
############################################################################### ###############################################################################
def main(gamename): def main(req,form):
# Print the required header that tells the browser how to render the text. """# Print the required header that tells the browser how to render the text.
#(currently done by error logger) #(currently done by error logger)
#print "Content-Type: text/plain\n\n" #print "Content-Type: text/plain\n\n"
gamename = form["game"]
#do stuff #do stuff
data = helper.header() data = helper.header()
@ -184,7 +184,7 @@ def main(gamename):
data +="\n<p>"+retstring+"</p>\n" data +="\n<p>"+retstring+"</p>\n"
data += helper.footer() data += helper.footer(req,form)
print data print data
"""

View file

@ -31,10 +31,24 @@ def debug(req,form, optstr = ""):
else: else:
req.write("Debug: "+optstr+"<br>\n") req.write("Debug: "+optstr+"<br>\n")
def footer(): def footer(req,form):
"""return html footer""" """return html footer"""
data = """ try:
</body></html> username=form["username"]
sessionid=form["sessionid"]
except: #not logged in
username = ""
sessionid = ""
if (username == "") or (sessionid == "") or ("logout" not in form.keys()):
data = """
<form method="post">
<input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s">
<input type=submit class="submit" name="logout" value="logout">
</form>""" % (sessionid, username)
else:
data = ""
data += """</body></html>
""" """
return data return data

View file

@ -26,13 +26,13 @@ def process_form(req,form):
game_overview_form(req,form) game_overview_form(req,form)
else: else:
req.write("Login incorrect. Please try again.<br>") req.write("Login incorrect. Please try again.<br>")
req.write(login_form()) req.write(login_form(req,form))
else: #no such user else: #no such user
req.write("Login incorrect. Please try again.-<br>") req.write("Login incorrect. Please try again.-<br>")
req.write(login_form()) req.write(login_form())
else: #one of (name,password) is missing: else: #one of (name,password) is missing:
req.write("Please enter your name and password.") req.write("Please enter your name and password.")
req.write(login_form()) req.write(login_form(req,form))
def game_overview_form(req,form): def game_overview_form(req,form):
@ -97,10 +97,10 @@ def game_overview_form(req,form):
""" % (sessionid, username) """ % (sessionid, username)
else: else:
data+= "Sorry, all your game slots are in use." data+= "Sorry, all your game slots are in use."
data+=helper.footer() data+=helper.footer(req,form)
req.write(data) req.write(data)
def login_form(): def login_form(req,form):
""" """
print welcome message and html form. print welcome message and html form.
""" """
@ -119,7 +119,7 @@ def login_form():
<input type="submit" class="submit" value="create account"> <input type="submit" class="submit" value="create account">
</form> </form>
""" % helper.generate_session_id() """ % helper.generate_session_id()
data += helper.footer() data += helper.footer(req,form)
return data return data
def navigation_bar(req,form): def navigation_bar(req,form):
@ -162,7 +162,7 @@ def main(req,form):
helper.debug(req,form) helper.debug(req,form)
#req.write(helper.footer()) #req.write(helper.footer())
if "sessionid" not in form.keys(): if "sessionid" not in form.keys():
req.write(login_form()) req.write(login_form(req,form))
elif ("game overview" in form.keys()) and ("username" in form.keys()) and ("sessionid" in form.keys()): elif ("game overview" in form.keys()) and ("username" in form.keys()) and ("sessionid" in form.keys()):
game_overview_form(req,form) game_overview_form(req,form)
elif ("logout" in form.keys()) and ("username" in form.keys()): elif ("logout" in form.keys()) and ("username" in form.keys()):

View file

@ -37,6 +37,9 @@ def handler(req):
elif ("play" in form.keys()) or ("refresh" in form.keys()): elif ("play" in form.keys()) or ("refresh" in form.keys()):
playgame = apache.import_module("playgame") playgame = apache.import_module("playgame")
playgame.main(req,form) playgame.main(req,form)
elif "logout" in form.keys():
logout = apache.import_module("logout")
logout.main(req,form)
else: else:
#call login.py #call login.py
login = apache.import_module("login") login = apache.import_module("login")

View file

@ -81,7 +81,7 @@ def main(req,form):
#print goban #print goban
data += goban.display_goban(gobandict,req,form) data += goban.display_goban(gobandict,req,form)
data += login.navigation_bar(req,form) data += login.navigation_bar(req,form)
data += helper.footer() data += helper.footer(req,form)
req.write(data) req.write(data)
else: else: