import psql,init_webgo,helper,gamecreation from mod_python import * def process_form(req,form): """ reads username and password from form """ #req.write("
"+"name="+form['name']+", password="+form['password']+"
") if form.keys() != []: if ("name" in form.keys()) and ("password" in form.keys()): #extract name and password name = form["name"] password = form["password"] sessionid = form["sessionid"] origpassword = psql.get_user_info(name,"password") #debug: helper.debug(req,form,'
--password:'+str(password)+' ---origpassword:'+str(origpassword)+'
') #check if user exists (else we would get an error string) if origpassword != "no such user": #no error message, now check password if password == origpassword: #login accepted psql.set_user_sessionid(name,sessionid) psql.set_user_timeout(name) #now display list of games. game_overview_form(req,form,name,sessionid) else: req.write("Login incorrect. Please try again.
") req.write(login_form()) else: #no such user req.write("Login incorrect. Please try again.-
") req.write(login_form()) else: #one of (name,password) is missing: req.write("Please enter your name and password.") req.write(login_form()) def game_overview_form(req,form,user,sessionid): """ gets: request object, util.FieldStorage form, name of user, sessionid. prints a form with the option to select,create and delete games. """ data = helper.header()+ """

Current Games:

""" gamelist = psql.get_user_game_list(user) #debug helper.debug(req,form,str(gamelist)+"
\n") #display list of current games counter = 10 tmp = "" for item in gamelist: if (item != None) and (item != "None"): tmp += ' %s
\n' % (item,item) #later write partners name and whether its our turn or not #data += "Your partner: %s." counter -= 1 if tmp == "": #no current games data += "You don't have any running games.\n" else: tmp += '\n' % sessionid tmp += '\n' % user data += tmp data += '\n\n
' #now comes the option for creating new games. data += "

New Game:

\n" if counter > 0: data+= "You have %s free game slots.
" % counter data += """
""" % (sessionid, user) else: data+= "Sorry, all your game slots are in use." #display "You have ... free game slots" + Button "create game" #bei "create game neue funktion zum Erstellen + Mitspieler aus Liste auswählen. data+=helper.footer() req.write(data) def login_form(): """ print welcome message and html form. """ data = helper.header() + """

Name:

Pasword:

""" % helper.generate_session_id() data += helper.footer() return data def navigation_bar(username,sessionid): """ gets username and sessionid writes the following to req: - a button to return to the game overview - a logout button returns string """ #TODO: buttons data="""
""" % (username,sessionid) return(data) def main(req,form): #debug helper.debug(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,form["username"],form["sessionid"]) else: process_form(req,form)