58 lines
No EOL
1.9 KiB
Python
58 lines
No EOL
1.9 KiB
Python
import helper,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,settings = {}):
|
|
"""
|
|
returns a HTML page containing one name and two password fields.
|
|
"""
|
|
|
|
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):
|
|
"""
|
|
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.
|
|
"""
|
|
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:
|
|
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:
|
|
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):
|
|
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
|
|
|
|
|