logout and refresh buttons in navigation_bar work. Cleaned some old stuff.

This commit is contained in:
phear 2005-09-20 09:51:12 +00:00
parent 18405f247a
commit 2630332479
5 changed files with 30 additions and 21 deletions

View file

@ -1,11 +1,5 @@
import psql,login import psql,login
def delete_game(gamename,username):
"""
get name of game and name of user.
remove game from game slot of user.
"""
def get_game_slot_of_game(player, gamename): def get_game_slot_of_game(player, gamename):
""" """
gets playername and game name, gets playername and game name,
@ -20,7 +14,7 @@ def get_game_slot_of_game(player, gamename):
def main(req,form): def main(req,form):
""" """
get the name of a game,request,util.FieldStorage. get request,util.FieldStorage.
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.
""" """

View file

@ -101,27 +101,39 @@ def login_form():
data += helper.footer() data += helper.footer()
return data return data
def navigation_bar(username,sessionid): def navigation_bar(req,form):
""" """
gets username and sessionid gets request object and util.FieldStorage form.
writes the following to req: writes the following to req:
- a button to return to the game overview - a button to return to the game overview
- a logout button - a logout button
returns string returns string
""" """
username = form["username"]
sessionid = form["sessionid"]
game = form["game"]
#TODO: buttons #TODO: buttons
data=""" data="""
<form method="post"> <form method="post">
<input type="hidden" name="username" value="%s"> <input type="hidden" name="username" value="%s">
<input type="hidden" name="sessionid" value="%s"> <input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="game" value="%s">
<input type="submit" id="submit" name="logout" value="logout"> <input type="submit" id="submit" name="logout" value="logout">
<input type="submit" id="submit" name="game overview" value="game overview"> <input type="submit" id="submit" name="game overview" value="game overview">
<input type="submit" id="submit" name="refresh" value="refresh">
</form> </form>
""" % (username,sessionid) """ % (username,sessionid,game)
return(data) return(data)
def logout(req,form):
"""
gets request object and util.FieldStorage form.
reads username from form and clears timeout and sessionid from users table.
"""
username = form["username"]
psql.set_user_sessionid(username,"")
psql.set_user_timeout(username,"")
def main(req,form): def main(req,form):
@ -130,9 +142,10 @@ def main(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())
elif ("create" in form.keys()) and ("username" in form.keys()):
pass
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()):
logout(req,form)
process_form(req,form)
else: else:
process_form(req,form) process_form(req,form)

View file

@ -35,7 +35,7 @@ def handler(req):
elif "delete" in form.keys(): elif "delete" in form.keys():
deletegame = apache.import_module("deletegame") deletegame = apache.import_module("deletegame")
deletegame.main(req,form) deletegame.main(req,form)
elif ("play" 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)
else: else:

View file

@ -41,7 +41,7 @@ def main(req,form):
""" """
display selected goban and manage user input. display selected goban and manage user input.
""" """
req.write(str(form.keys())+"<hr>") helper.debug(req,form,str(form.keys())+"<hr>")
try: try:
gamename = form["game"] gamename = form["game"]
@ -61,8 +61,6 @@ def main(req,form):
if foundx: if foundx:
if is_my_turn(req,form,gobandict): if is_my_turn(req,form,gobandict):
(gobandict,retstring) = goban.process_form(req,form,gobandict) (gobandict,retstring) = goban.process_form(req,form,gobandict)
else:
pass
#do stuff #do stuff
data = helper.header() data = helper.header()
@ -81,7 +79,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(form["username"],form["sessionid"]) data += login.navigation_bar(req,form)
data += helper.footer() data += helper.footer()
req.write(data) req.write(data)

View file

@ -182,6 +182,9 @@ def update_database_field(table,column,new_value,uniqname,uniqvalue):
name of unique identifier and name of unique identifier and
value of unique identifier for field (e.g. 'username' and 'testuser') value of unique identifier for field (e.g. 'username' and 'testuser')
""" """
if new_value == "":
executestring ="UPDATE %s SET %s = DEFAULT WHERE %s = '%s'" % (table,column,uniqname,uniqvalue)
else:
executestring ="UPDATE %s SET %s = '%s' WHERE %s = '%s'" % (table,column,new_value,uniqname,uniqvalue) executestring ="UPDATE %s SET %s = '%s' WHERE %s = '%s'" % (table,column,new_value,uniqname,uniqvalue)
sql_one_liner(executestring) sql_one_liner(executestring)
@ -233,11 +236,12 @@ def set_user_sessionid(username,sessionid):
""" """
update_users_table_field(username,"sessionid",sessionid) update_users_table_field(username,"sessionid",sessionid)
def set_user_timeout(username): def set_user_timeout(username,timeout=None):
""" """
gets username, sets timeout to time.time + 30min gets username, sets timeout to time.time + 30min
""" """
import time import time
if timeout == None:
timeout = int(time.time()) + 900 #current time in seconds + seconds for session timeout = int(time.time()) + 900 #current time in seconds + seconds for session
update_users_table_field(username,"timeout",timeout) update_users_table_field(username,"timeout",timeout)