started converting to clearsilver templates.

This commit is contained in:
phear 2005-12-11 19:00:50 +00:00
parent 0a6290d480
commit 025f4824fb
7 changed files with 62 additions and 34 deletions

View file

@ -3,11 +3,12 @@ import helper,database
from sets import Set as set from sets import Set as set
from cherrypy import cpg from cherrypy import cpg
from cherrypy.lib import httptools 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): def navigation_bar(req,form):
"" " "" "
@ -70,36 +71,29 @@ class Login:
else: else:
return self.process_form(username,password) return self.process_form(username,password)
def login_form(self): def login_form(self,message=""):
""" """
print welcome message and html form. print welcome message and html form.
""" """
hdf=neo_util.HDF()
data = helper.header() hdf.setValue("Data.Message",message)
data += """ cs= neo_cs.CS(hdf)
<form method="post"> cs.parseFile("templates/login_form.cs")
<p>Name:<br> return cs.render()
<input name="username" type="text" class="text" size="20"></p>
<p>Password:<br>
<input name="password" type="text" class="text" size="20"></p>
<p><input type="submit" class="submit" value="login"></p>
</form>
<a href="/createaccount"> create account</a><br>
"""
data += helper.footer()
return data
def process_form(self,username,password): def process_form(self,username,password):
""" """
gets username and password, checks for validity, eventually the user is logged in. gets username and password, checks for validity, eventually the user is logged in.
TODO: check for session timeout TODO: check for session timeout
""" """
data = helper.header()
sessionid = cpg.request.sessionMap["_sessionId"] sessionid = cpg.request.sessionMap["_sessionId"]
myuser = database.Users.byUsername(username) try:
origpassword = myuser.password myuser = database.Users.byUsername(username)
if password == origpassword: origpassword = myuser.password
except:
origpassword = ""
if origpassword != "" and password == origpassword:
#login accepted #login accepted
myuser.sessionid = sessionid myuser.sessionid = sessionid
myuser.set_timeout() myuser.set_timeout()
@ -108,9 +102,8 @@ class Login:
httptools.redirect("/overview") httptools.redirect("/overview")
#data += "Login accepted." #data += "Login accepted."
else: else:
data += "Login incorrect. Please try again.<br>" message = "Login incorrect. Please try again.<br>"
data += self.login_form() data = self.login_form(message)
data += helper.footer()
return data return data

18
main.py
View file

@ -2,15 +2,19 @@ import sys, traceback,string,time
import login,createaccount,helper,gamecreation,playgame import login,createaccount,helper,gamecreation,playgame
from cherrypy import cpg 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: class WebGoSite:
def index(self): def index(self):
data = helper.header() hdf=neo_util.HDF()
data += """ This is WebGo.<br> cs= neo_cs.CS(hdf)
<a href="/login">login</a><br> cs.parseFile("templates/main.cs")
<a href="/createaccount">create an account</a><br> return cs.render()
"""
data += helper.footer()
return data
index.exposed = True index.exposed = True
cpg.root = WebGoSite() cpg.root = WebGoSite()

View file

@ -1,4 +1,4 @@
import goban,helper,database,login,gnugo import helper,database,login,gnugo
import string import string
from cherrypy import cpg from cherrypy import cpg
from cherrypy.lib import httptools from cherrypy.lib import httptools

2
templates/footer.cs Normal file
View file

@ -0,0 +1,2 @@
</body></html>

11
templates/header.cs Normal file
View file

@ -0,0 +1,11 @@
<html>
<head>
<title>WebGo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<link rel="stylesheet" media="screen" href="/default.css" type="text/css" />
</head>
<h1> WebGo </h1>
<body>

11
templates/login_form.cs Normal file
View file

@ -0,0 +1,11 @@
<?cs include:"templates/header.cs" ?>
<?cs var:Data.Message ?>
<form method="post">
<p>Name:<br>
<input name="username" type="text" class="text" size="20"></p>
<p>Password:<br>
<input name="password" type="text" class="text" size="20"></p>
<p><input type="submit" class="submit" value="login"></p>
</form>
<a href="/createaccount"> create account</a><br>
<?cs include:"templates/footer.cs" ?>

7
templates/main.cs Normal file
View file

@ -0,0 +1,7 @@
<?cs include:"templates/header.cs" ?>
This is WebGo.<br>
<a href="/login">login</a><br>
<a href="/createaccount">create an account</a><br>
<?cs include:"templates/footer.cs" ?>