From 025f4824fb221efb909fa5d0bc51975964145ebe Mon Sep 17 00:00:00 2001 From: phear Date: Sun, 11 Dec 2005 19:00:50 +0000 Subject: [PATCH] started converting to clearsilver templates. --- login.py | 45 +++++++++++++++++------------------------ main.py | 18 ++++++++++------- playgame.py | 2 +- templates/footer.cs | 2 ++ templates/header.cs | 11 ++++++++++ templates/login_form.cs | 11 ++++++++++ templates/main.cs | 7 +++++++ 7 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 templates/footer.cs create mode 100644 templates/header.cs create mode 100644 templates/login_form.cs create mode 100644 templates/main.cs diff --git a/login.py b/login.py index c16d4cd..eba3f0f 100755 --- a/login.py +++ b/login.py @@ -3,11 +3,12 @@ import helper,database from sets import Set as set from cherrypy import cpg from cherrypy.lib import httptools -""" +#clearsilver templates +import neo_cgi +import neo_util # you must import neo_cgi first... +import neo_cs # you must import neo_cgi first... - -""" """ def navigation_bar(req,form): "" " @@ -70,36 +71,29 @@ class Login: else: return self.process_form(username,password) - def login_form(self): + def login_form(self,message=""): """ print welcome message and html form. """ - - data = helper.header() - data += """ -
-

Name:
-

-

Password:
-

-

-
- create account
- """ - data += helper.footer() - return data - + hdf=neo_util.HDF() + hdf.setValue("Data.Message",message) + cs= neo_cs.CS(hdf) + cs.parseFile("templates/login_form.cs") + return cs.render() + def process_form(self,username,password): """ gets username and password, checks for validity, eventually the user is logged in. TODO: check for session timeout """ - data = helper.header() sessionid = cpg.request.sessionMap["_sessionId"] - myuser = database.Users.byUsername(username) - origpassword = myuser.password - if password == origpassword: + try: + myuser = database.Users.byUsername(username) + origpassword = myuser.password + except: + origpassword = "" + if origpassword != "" and password == origpassword: #login accepted myuser.sessionid = sessionid myuser.set_timeout() @@ -108,9 +102,8 @@ class Login: httptools.redirect("/overview") #data += "Login accepted." else: - data += "Login incorrect. Please try again.
" - data += self.login_form() - data += helper.footer() + message = "Login incorrect. Please try again.
" + data = self.login_form(message) return data diff --git a/main.py b/main.py index 565ff98..8b4edeb 100755 --- a/main.py +++ b/main.py @@ -2,15 +2,19 @@ import sys, traceback,string,time import login,createaccount,helper,gamecreation,playgame from cherrypy import cpg +#clearsilver templates +import neo_cgi +import neo_util # you must import neo_cgi first... +import neo_cs # you must import neo_cgi first... + + class WebGoSite: def index(self): - data = helper.header() - data += """ This is WebGo.
- login
- create an account
- """ - data += helper.footer() - return data + hdf=neo_util.HDF() + cs= neo_cs.CS(hdf) + cs.parseFile("templates/main.cs") + return cs.render() + index.exposed = True cpg.root = WebGoSite() diff --git a/playgame.py b/playgame.py index 6e256d9..ae6b2ac 100644 --- a/playgame.py +++ b/playgame.py @@ -1,4 +1,4 @@ -import goban,helper,database,login,gnugo +import helper,database,login,gnugo import string from cherrypy import cpg from cherrypy.lib import httptools diff --git a/templates/footer.cs b/templates/footer.cs new file mode 100644 index 0000000..c20b863 --- /dev/null +++ b/templates/footer.cs @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/templates/header.cs b/templates/header.cs new file mode 100644 index 0000000..bf92882 --- /dev/null +++ b/templates/header.cs @@ -0,0 +1,11 @@ + + + WebGo + + + + + + +

WebGo

+ \ No newline at end of file diff --git a/templates/login_form.cs b/templates/login_form.cs new file mode 100644 index 0000000..41efc8a --- /dev/null +++ b/templates/login_form.cs @@ -0,0 +1,11 @@ + + +
+

Name:
+

+

Password:
+

+

+
+ create account
+ \ No newline at end of file diff --git a/templates/main.cs b/templates/main.cs new file mode 100644 index 0000000..7ba9a52 --- /dev/null +++ b/templates/main.cs @@ -0,0 +1,7 @@ + + +This is WebGo.
+login
+create an account
+ + \ No newline at end of file