accoutn creation works with clearsilver template.
This commit is contained in:
parent
6a461c441e
commit
a70d382c93
4 changed files with 81 additions and 37 deletions
|
@ -1,13 +1,7 @@
|
|||
import helper,database
|
||||
#,database
|
||||
|
||||
maxuser = 1000
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
class CreateAccount:
|
||||
def index(self,username = None, password1 = None, password2 = None):
|
||||
"""
|
||||
|
@ -19,24 +13,16 @@ class CreateAccount:
|
|||
return self.display_create_form()
|
||||
|
||||
|
||||
def display_create_form(self):
|
||||
def display_create_form(self,settings = {}):
|
||||
"""
|
||||
returns a HTML page containing one name and two password fields.
|
||||
"""
|
||||
data = helper.header()
|
||||
data += """
|
||||
<form method="post">
|
||||
<p>Your username:<br>
|
||||
<input name="username" type="text" class="text" size="20"></p>
|
||||
<p>Your Password:<br>
|
||||
<input name="password1" type="text" class="text" size="20"></p>
|
||||
<p>Please retype your Password:<br>
|
||||
<input name="password2" type="text" class="text" size="20"></p>
|
||||
<p><input type="submit" class="submit" value="create account"></p>
|
||||
</form>
|
||||
"""
|
||||
data += helper.footer()
|
||||
return(data)
|
||||
|
||||
try:#do we get a settings dictionary from process_form?
|
||||
x = settings["Data.NotCreated"]
|
||||
except:#no, this is the first display of the form -> set needed variables.
|
||||
settings["Data.NotCreated"] = 1
|
||||
return helper.cs_render("templates/createaccount.cs",settings)
|
||||
|
||||
|
||||
def process_form(self,username, password1, password2):
|
||||
|
@ -45,26 +31,28 @@ class CreateAccount:
|
|||
If all data is there and correct, create the named user and return a 'success'
|
||||
page. Else fail with detailed error.
|
||||
"""
|
||||
data = helper.header()
|
||||
if (password1 == password2):
|
||||
#try:
|
||||
#.add_webgo_user(username,password1)
|
||||
newuser = database.Users(username=username,password=password1)
|
||||
created_user = True
|
||||
#except:
|
||||
# #user already exists
|
||||
# created_user = False
|
||||
settings = {}
|
||||
settings["Data.NotCreated"] = 1
|
||||
|
||||
if (password1 == password2):
|
||||
try:
|
||||
newuser = database.Users(username=username,password=password1)
|
||||
created_user = 1
|
||||
except:
|
||||
created_user = 0
|
||||
if created_user:
|
||||
data += ('User %s has been successfully created. Click <a href="/login">here</a> to login.<br>' % username)
|
||||
settings["Data.Message"] = 'User %s has been successfully created. Click <a href="/login">here</a> to login.<br>' % username
|
||||
settings["Data.NotCreated"] = 0
|
||||
return self.display_create_form(settings)
|
||||
else:
|
||||
data += ("User %s already exists. Please retry with another name." % username)
|
||||
data += self.display_create_form()
|
||||
settings["Data.Message"] = "User %s already exists. Please retry with another name." % username
|
||||
return self.display_create_form(settings)
|
||||
else:
|
||||
if (password1 == "") or (password2 == "") or (password1 != password2):
|
||||
data += ("Both given passwords have to be the same and non-empty.<br>")
|
||||
data += self.display_create_form()
|
||||
data += helper.footer()
|
||||
return data
|
||||
settings["Data.Message"] = "Both given passwords have to be the same and non-empty.<br>"
|
||||
return self.display_create_form(settings)
|
||||
else:
|
||||
return self.display_create_form()
|
||||
index.exposed = True
|
||||
|
||||
|
16
templates/createaccount.cs
Normal file
16
templates/createaccount.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?cs include:"templates/header.cs" ?>
|
||||
|
||||
<?cs var:Data.Message ?>
|
||||
<?cs if:#Data.NotCreated ?>
|
||||
<form method="post">
|
||||
<p>Your username:<br>
|
||||
<input name="username" type="text" class="text" size="20"></p>
|
||||
<p>Your Password:<br>
|
||||
<input name="password1" type="text" class="text" size="20"></p>
|
||||
<p>Please retype your Password:<br>
|
||||
<input name="password2" type="text" class="text" size="20"></p>
|
||||
<p><input type="submit" class="submit" value="create account"></p>
|
||||
</form>
|
||||
<?cs /if ?>
|
||||
|
||||
<?cs include:"templates/footer.cs" ?>
|
25
templates/gamecreation.cs
Normal file
25
templates/gamecreation.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?cs include:"templates/header.cs" ?>
|
||||
|
||||
<?cs include:"templates/macros.cs" ?>
|
||||
|
||||
<?cs var:Data.Message ?>
|
||||
|
||||
<form method="post">
|
||||
<p>Player One (Black):
|
||||
<?cs call:select_list(Data.Userlist,'player1',Data.Username) ?>
|
||||
</p>
|
||||
<p>Player Two (White):
|
||||
<?cs call:select_list(Data.Userlist,'player2','') ?>
|
||||
</p>
|
||||
<p>Goban Size:
|
||||
<select name="gobansize">
|
||||
<option> 9 </option>
|
||||
<option> 13 </option>
|
||||
<option> 19 </option>
|
||||
</select>
|
||||
fields </p>
|
||||
<p>Optional name for game: <input type="text" name="description" size="20" class="text"></p>
|
||||
<input type="submit" class="submit" value="create game">
|
||||
</form>
|
||||
|
||||
<?cs include:"templates/footer.cs" ?>
|
15
templates/macros.cs
Normal file
15
templates/macros.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?cs def:select_list(itemlist, listname, selected) ?><?cs
|
||||
#create a drop down list out of the items of itemlist.
|
||||
# use 'listname' as name for the select tag.
|
||||
#use 'selected' as preselected value.
|
||||
?>
|
||||
<select name="<?cs var:listname ?>">
|
||||
<?cs each:item = itemlist ?>
|
||||
<?cs if:item == selected ?>
|
||||
<option selected> <?cs var:item ?> </option>
|
||||
<?cs else ?>
|
||||
<option > <?cs var:item ?> </option>
|
||||
<?cs /if ?>
|
||||
<?cs /each ?>
|
||||
</select>
|
||||
<?cs /def ?>
|
Loading…
Reference in a new issue