webgo/createaccount.py

70 lines
No EOL
2 KiB
Python

import helper,database
#,database
maxuser = 1000
"""
"""
class CreateAccount:
def index(self,username = None, password1 = None, password2 = None):
"""
checks if there are some parameters from the form. If not, displays creation form. Else processes form data
"""
if username != None and password1 != None and password2 != None:
return self.process_form(username,password1,password2)
else:
return self.display_create_form()
def display_create_form(self):
"""
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)
def process_form(self,username, password1, password2):
"""
gets username, password1 and password2.
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
if created_user:
data += ('User %s has been successfully created. Click <a href="/login">here</a> to login.<br>' % username)
else:
data += ("User %s already exists. Please retry with another name." % username)
data += self.display_create_form()
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
index.exposed = True