timeout bug fixed. main.handler() now automatically updates timeout.

This commit is contained in:
phear 2005-09-14 15:08:44 +00:00
parent 230f04c758
commit e7e9c72e54
2 changed files with 17 additions and 11 deletions

View file

@ -1,12 +1,10 @@
import psql,init_webgo,helper,gamecreation import psql,init_webgo,helper,gamecreation
import time
from mod_python import * from mod_python import *
def process_form(req,form): def process_form(req,form):
""" """
reads username and password from form reads username and password from form
""" """
#if form == empty (which means if page is displayed for the first time):
req.write(str(form.keys())) req.write(str(form.keys()))
#req.write("<br>"+"name="+form['name']+", password="+form['password']+"<hr>") #req.write("<br>"+"name="+form['name']+", password="+form['password']+"<hr>")
if form.keys() != []: if form.keys() != []:
@ -80,12 +78,8 @@ def game_overview_form(req,user,sessionid):
#display "You have ... free game slots" + Button "create game" #display "You have ... free game slots" + Button "create game"
#bei "create game neue funktion zum Erstellen + Mitspieler aus Liste auswählen. #bei "create game neue funktion zum Erstellen + Mitspieler aus Liste auswählen.
data+=helper.footer() data+=helper.footer()
#check for timeout: req.write(data)
if (psql.get_user_info(user,'timeout') >= int(time.time())) and (sessionid == psql.get_user_info(user,'sessionid')):
req.write(data)
else:
req.write('your session timed out. -- sessionid: '+sessionid+' -- <hr>')
def login_form(): def login_form():
""" """
print welcome message and html form. print welcome message and html form.

18
main.py
View file

@ -4,11 +4,11 @@ simple cgi wrapper for a cgi script, prints the error of the script as html
taken from http://gnosis.cx/publish/programming/feature_5min_python.html taken from http://gnosis.cx/publish/programming/feature_5min_python.html
modified a little modified a little
""" """
import sys, traceback,string,time
import init_webgo,psql
from mod_python import * from mod_python import *
import sys, traceback,string
import init_webgo
DEBUG = 1 DEBUG = 1
@ -23,10 +23,23 @@ def handler(req):
#load form, then delegate request #load form, then delegate request
form = util.FieldStorage(req) form = util.FieldStorage(req)
try:
sessionid=form["sessionid"]
username=form["username"]
except:
sessionid=""
username=""
foundx = False foundx = False
for item in form.keys(): for item in form.keys():
if string.find(item,").x") > 0: if string.find(item,").x") > 0:
foundx = True foundx = True
#if sessionid=sesssionid and time < timeout:
# set_timeout
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(): if "create" in form.keys():
gamecreation = apache.import_module("gamecreation") gamecreation = apache.import_module("gamecreation")
gamecreation.main(req,form) gamecreation.main(req,form)
@ -42,7 +55,6 @@ def handler(req):
login.main(req,form) login.main(req,form)
return apache.OK return apache.OK
except: except:
import time
errtime = '----- '+ time.ctime(time.time()) +' -----\n' errtime = '----- '+ time.ctime(time.time()) +' -----\n'
errlog = open('/tmp/cgi_errors.log', 'a') errlog = open('/tmp/cgi_errors.log', 'a')
errlog.write(errtime) errlog.write(errtime)