diff --git a/createaccount.py b/createaccount.py
index 23e0215..31d93b3 100644
--- a/createaccount.py
+++ b/createaccount.py
@@ -1,4 +1,4 @@
-import helper,psql
+import helper,database
maxuser = 1000
@@ -42,7 +42,8 @@ def process_form(req,form):
except:
username = ""
if (username != "") and (password1 != "") and (password2 != "") and (password1 == password2):
- psql.add_webgo_user(username,password1)
+ newuser = database.Users(username=username,password=password1)
+ #.add_webgo_user(username,password1)
req.write("User %s has been successfully created. Click the following button to login:
" % username)
data = """
\n'
if helper.clean_list(gamelist) != []:
@@ -153,9 +156,10 @@ def logout(req,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,"")
-
+ myuser = database.Users.byUsername(username)
+ myuser.sessionid = ""
+ myuser.timeout = 0
+
def main(req,form):
#debug
diff --git a/logout.py b/logout.py
new file mode 100644
index 0000000..5949eac
--- /dev/null
+++ b/logout.py
@@ -0,0 +1,13 @@
+import database
+import login
+
+def process_form(req,form):
+ username = form["username"]
+ myuser = database.Users.byUsername(username)
+ myuser.sessionid = None
+
+ login.main(req,form)
+
+
+def main(req,form):
+ process_form(req,form)
\ No newline at end of file
diff --git a/main.py b/main.py
index 2ca446a..fe5f512 100755
--- a/main.py
+++ b/main.py
@@ -1,5 +1,5 @@
import sys, traceback,string,time
-import init_webgo,psql
+import init_webgo,database
from mod_python import *
@@ -24,33 +24,45 @@ def handler(req):
sessionid=""
username=""
- #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():
- gamecreation = apache.import_module("gamecreation")
- gamecreation.main(req,form)
- elif "delete" in form.keys():
- deletegame = apache.import_module("deletegame")
- deletegame.main(req,form)
- elif ("play" in form.keys()) or ("refresh" in form.keys()):
- playgame = apache.import_module("playgame")
- playgame.main(req,form)
- elif "logout" in form.keys():
- logout = apache.import_module("logout")
- logout.main(req,form)
+ try:
+ myuser = database.Users.byUsername(username)
+ valid_user = True
+ except:
+ #no such user
+ valid_user = False
+
+ if username != "" and valid_user:
+ if (myuser.timeout > int(time.time())) and (sessionid == myuser.sessionid):
+ myuser.set_timeout()
+
+ if "create" in form.keys():
+ gamecreation = apache.import_module("gamecreation")
+ gamecreation.main(req,form)
+ elif "delete" in form.keys():
+ deletegame = apache.import_module("deletegame")
+ deletegame.main(req,form)
+ elif ("play" in form.keys()) or ("refresh" in form.keys()):
+ playgame = apache.import_module("playgame")
+ playgame.main(req,form)
+ elif "logout" in form.keys():
+ logout = apache.import_module("logout")
+ logout.main(req,form)
+ else:
+ #call login.py
+ login = apache.import_module("login")
+ login.main(req,form)
else:
#call login.py
login = apache.import_module("login")
login.main(req,form)
else:
if "createaccount" in form.keys():
- createaccount = apache.import_module("createaccount")
- createaccount.main(req,form)
+ createaccount = apache.import_module("createaccount")
+ createaccount.main(req,form)
else:#call login.py
login = apache.import_module("login")
login.main(req,form)
+
return apache.OK
except:
diff --git a/playgame.py b/playgame.py
index c1cbc70..edeee15 100644
--- a/playgame.py
+++ b/playgame.py
@@ -1,4 +1,4 @@
-import goban,helper,psql,login,gnugo
+import goban,helper,database,login,gnugo
import string
DEBUG = 1
@@ -26,14 +26,15 @@ def create_gobandict(req,form,gamename):
loads sgf, transforms it to dict, writes stuff like player names to dict
returns dict
"""
- #read goban table from database
- tmplist = psql.read_table(gamename)
- #make a dictionary out of the list
- tmpdict = psql.fetchall_list_to_goban_dict(tmplist)
- sgf = psql.get_sgf(gamename)
+ #read goban sgf from database
+ mygame = database.GobanTable.byName(gamename)
+ sgf = mygame.sgf
gobandict = gnugo.parse_static_gnugo_sgf(sgf)
- for key in ["player1","player2","turn_number","name","sgf"]:
- gobandict[key] = tmpdict[key]
+ gobandict["player1"] = mygame.player1
+ gobandict["player2"] = mygame.player2
+ gobandict["turn_number"] = mygame.turn_number
+ gobandict["name"] = mygame.name
+ gobandict["sgf"] = sgf
return gobandict
def main(req,form):
@@ -67,7 +68,7 @@ def main(req,form):
gobandict = create_gobandict(req,form,gamename)
else:
- helper.debug(req,form,"its not my turn.")
+ helper.debug(req,form,"it's not my turn.")
data += """
Turn number: %s. %s plays.\n
""" % (str(gobandict["turn_number"]), (string.capitalize(gobandict["play"])))
@@ -75,7 +76,7 @@ def main(req,form):
#if yes: print 'your move' and display goban and process move
#if not: print '...s move' and display goban.
if is_my_turn(req,form,gobandict):
- data += "
Its your turn.
\n"
+ data += "
It's your turn.
\n"
else:
data += "
This is not your turn. You have to wait for the move of the other player.
\n"
#print goban