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
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):
"""
gets playername and game name,
@ -20,7 +14,7 @@ def get_game_slot_of_game(player, gamename):
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
delete game from database.
"""

View file

@ -101,27 +101,39 @@ def login_form():
data += helper.footer()
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:
- a button to return to the game overview
- a logout button
returns string
"""
username = form["username"]
sessionid = form["sessionid"]
game = form["game"]
#TODO: buttons
data="""
<form method="post">
<input type="hidden" name="username" 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="game overview" value="game overview">
<input type="submit" id="submit" name="refresh" value="refresh">
</form>
""" % (username,sessionid)
""" % (username,sessionid,game)
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):
@ -130,9 +142,10 @@ def main(req,form):
#req.write(helper.footer())
if "sessionid" not in form.keys():
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()):
game_overview_form(req,form)
elif ("logout" in form.keys()) and ("username" in form.keys()):
logout(req,form)
process_form(req,form)
else:
process_form(req,form)

View file

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

View file

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

View file

@ -182,6 +182,9 @@ def update_database_field(table,column,new_value,uniqname,uniqvalue):
name of unique identifier and
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)
sql_one_liner(executestring)
@ -233,11 +236,12 @@ def set_user_sessionid(username,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
"""
import time
if timeout == None:
timeout = int(time.time()) + 900 #current time in seconds + seconds for session
update_users_table_field(username,"timeout",timeout)