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 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 += """
<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>
"""
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.<br>"
data += self.login_form()
data += helper.footer()
message = "Login incorrect. Please try again.<br>"
data = self.login_form(message)
return data

18
main.py
View file

@ -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.<br>
<a href="/login">login</a><br>
<a href="/createaccount">create an account</a><br>
"""
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()

View file

@ -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

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" ?>