def __init__(self, **params): gui.Table.__init__(self, **params) self.value = gui.Form() self.engine = None def btnLogin(btn): self.engine.doLogin() def btnRegister(btn): g.gameState = MENU_REGISTER if g.tcpConn is None: g.gameEngine.initConnection() self.tr() self.td(gui.Input(name="username", value="Username")) self.tr() self.td(gui.Password(name="password", value="password")) self.tr() self.td(gui.Spacer(0, 30)) self.tr() btn = gui.Button("Login", width=120) btn.connect(gui.CLICK, btnLogin, None) self.td(btn) self.tr() self.td(gui.Spacer(0, 5)) self.tr() btn = gui.Button("Register", width=120) btn.connect(gui.CLICK, btnRegister, None) self.td(btn)
def __init__(self, **params): gui.Table.__init__(self, **params) self.value = gui.Form() self.engine = None def btnRegister(btn): def isLoginLegal(username, password): if len(username) > 3 and len(password) > 3: return True else: print "username and password must be larger 3 characters" def isStringLegal(string): restricted = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' for i in range(len(string)): if string[i] not in restricted: # todo: msgbox (not valid) print "name is not valid" return False return True def checkPasswords(password1, password2): if password1 == password2: return True username = self.value.items()[0][1] password = self.value.items()[1][1] passwordConfirm = self.value.items()[2][1] if isLoginLegal(username, password): if checkPasswords(password, passwordConfirm): if isStringLegal(username): g.tcpConn.sendNewAccount(username, password) print "Created user " + username # return to login screen g.gameEngine.setState(MENU_LOGIN) else: # todo: msgbox print "passwords didn't match" def btnCancel(btn): g.gameState = MENU_LOGIN self.tr() self.td(gui.Label('Username:'******'Password:'******'Confirm password:', color=(255, 255, 255))) self.tr() self.td(gui.Password(name="passwordConfirm", value="password")) self.tr() self.td(gui.Spacer(0, 30)) self.tr() btn = gui.Button("Create", width=120) btn.connect(gui.CLICK, btnRegister, None) self.td(btn) self.tr() self.td(gui.Spacer(0, 5)) self.tr() btn = gui.Button("Cancel", width=120) btn.connect(gui.CLICK, btnCancel, None) self.td(btn)
def __init__(self, **params): gui.Table.__init__(self, **params) self.value = gui.Form() self.engine = None def btnRegister(btn): def isLoginLegal(username, password): if len(username) > 3 and len(password) > 3: return True else: alertMessageDialog( msg= 'Username and password must be larger than 3 characters.', title='An error occured') def isStringLegal(string): restricted = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' for i in range(len(string)): if string[i] not in restricted: # todo: msgbox (not valid) alertMessageDialog( msg= 'The name is not valid! The name may only contain a-z and 0-9.', title='An error occured') return False return True def checkPasswords(password1, password2): if password1 == password2: return True username = self.value.items()[0][1] password = self.value.items()[1][1] passwordConfirm = self.value.items()[2][1] if isLoginLegal(username, password): if checkPasswords(password, passwordConfirm): if isStringLegal(username): g.tcpConn.sendNewAccount(username, password) else: # todo: msgbox alertMessageDialog(msg='The passwords don\'t match.', title='An error occured') def btnCancel(btn): g.gameState = MENU_LOGIN self.tr() self.td(gui.Label('Username:'******'Password:'******'Confirm password:', color=(255, 255, 255))) self.tr() self.td(gui.Password(name="passwordConfirm", value="password")) self.tr() self.td(gui.Spacer(0, 30)) self.tr() btn = gui.Button("Create", width=120) btn.connect(gui.CLICK, btnRegister, None) self.td(btn) self.tr() self.td(gui.Spacer(0, 5)) self.tr() btn = gui.Button("Cancel", width=120) btn.connect(gui.CLICK, btnCancel, None) self.td(btn)