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
|
import helper,database
|
||||||
#,database
|
|
||||||
|
|
||||||
maxuser = 1000
|
maxuser = 1000
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
class CreateAccount:
|
class CreateAccount:
|
||||||
def index(self,username = None, password1 = None, password2 = None):
|
def index(self,username = None, password1 = None, password2 = None):
|
||||||
"""
|
"""
|
||||||
|
@ -19,24 +13,16 @@ class CreateAccount:
|
||||||
return self.display_create_form()
|
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.
|
returns a HTML page containing one name and two password fields.
|
||||||
"""
|
"""
|
||||||
data = helper.header()
|
|
||||||
data += """
|
try:#do we get a settings dictionary from process_form?
|
||||||
<form method="post">
|
x = settings["Data.NotCreated"]
|
||||||
<p>Your username:<br>
|
except:#no, this is the first display of the form -> set needed variables.
|
||||||
<input name="username" type="text" class="text" size="20"></p>
|
settings["Data.NotCreated"] = 1
|
||||||
<p>Your Password:<br>
|
return helper.cs_render("templates/createaccount.cs",settings)
|
||||||
<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)
|
|
||||||
|
|
||||||
|
|
||||||
def process_form(self,username, password1, password2):
|
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'
|
If all data is there and correct, create the named user and return a 'success'
|
||||||
page. Else fail with detailed error.
|
page. Else fail with detailed error.
|
||||||
"""
|
"""
|
||||||
data = helper.header()
|
settings = {}
|
||||||
|
settings["Data.NotCreated"] = 1
|
||||||
|
|
||||||
if (password1 == password2):
|
if (password1 == password2):
|
||||||
#try:
|
try:
|
||||||
#.add_webgo_user(username,password1)
|
newuser = database.Users(username=username,password=password1)
|
||||||
newuser = database.Users(username=username,password=password1)
|
created_user = 1
|
||||||
created_user = True
|
except:
|
||||||
#except:
|
created_user = 0
|
||||||
# #user already exists
|
|
||||||
# created_user = False
|
|
||||||
if created_user:
|
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:
|
else:
|
||||||
data += ("User %s already exists. Please retry with another name." % username)
|
settings["Data.Message"] = "User %s already exists. Please retry with another name." % username
|
||||||
data += self.display_create_form()
|
return self.display_create_form(settings)
|
||||||
else:
|
else:
|
||||||
if (password1 == "") or (password2 == "") or (password1 != password2):
|
if (password1 == "") or (password2 == "") or (password1 != password2):
|
||||||
data += ("Both given passwords have to be the same and non-empty.<br>")
|
settings["Data.Message"] = "Both given passwords have to be the same and non-empty.<br>"
|
||||||
data += self.display_create_form()
|
return self.display_create_form(settings)
|
||||||
data += helper.footer()
|
else:
|
||||||
return data
|
return self.display_create_form()
|
||||||
index.exposed = True
|
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