def submitCreateUser(self,*a): admin = User(self.create_adminUser.get(), self.create_adminPass.get()) newUser = User(self.create_newUser.get(), self.create_newPass.get()) newUserSecretQ = self.create_secretQ.get() newUserSecretA = self.create_secretA.get() reEnteredPass = self.create_newPass2.get() # Error checking: wrong admin username-password combo if not admin.auth(): self.create_notifier.config(text='Wrong administrator credentials.', foreground='red') return # Error checking: entered admin account isn't root elif not admin.checkIfRoot(): message = 'User ' + admin.username + ' is not an administrator.' self.create_notifier.config(text=message, foreground='red') return # Error checking: blank fields in new user input fields if newUser.username=="" or newUser.password=="" or newUserSecretA=="" or newUserSecretQ=="" or reEnteredPass=="": self.create_notifier.config(text='Please fill up all fields.', foreground='red') return # Error checking: username already taken elif User.userExists(newUser.username): message = 'Username ' + newUser.username + ' is already taken.' self.create_notifier.config(text=message, foreground='red') return # Error checking: two password fields don't match elif newUser.password!=reEnteredPass: self.create_notifier.config(text="Passwords don't match", foreground='red') return # Create the new user newUser.saveUser(newUserSecretQ, newUserSecretA, isRoot=self.create_isAdmin.get()) self.create_notifier.config(text="New user created.", foreground='darkgreen') self.clearCreateAccountEntries() # Refresh the Reset Password tab's user drop down menu choices self.reset_userSelector.comboBox.config(values=User.listUsernames())
def initUI(self): self.parent.geometry("570x570") # Notebook self.notebook = Notebook(self.parent) self.notes={} for i in ["Log In", "Create Account", "Change Password", "Reset Forgotten Password"]: self.notes[i]=Frame(self.notebook) self.notebook.add(self.notes[i],text=i) self.notebook.pack(fill=BOTH,expand=1) self.notebook.pack_propagate(0) # Log in widgets logInFrame = self.notes["Log In"] Label(logInFrame, text="Enter username").pack() self.logIn_username = Entry(logInFrame) self.logIn_username.pack() Label(logInFrame, text="Enter password").pack() self.logIn_password = Entry(logInFrame,show="*") self.logIn_password.pack() ## Submit button and text notifier Label(logInFrame, text="").pack() self.logIn_submit = Button(logInFrame, text="Submit", command=self.submitLogIn) self.logIn_submit.pack() self.logIn_notifier = Label(logInFrame) self.logIn_notifier.pack() self.logInEntries.append(self.logIn_username) self.logInEntries.append(self.logIn_password) #press enter to submit self.logIn_username.focus() self.logIn_password.bind("<Return>",self.submitLogIn) # Create account widgets ## Admin account widgets createFrame = self.notes["Create Account"] Label(createFrame, text="Enter administrator username").pack() self.create_adminUser = Entry(createFrame) self.create_adminUser.pack() Label(createFrame, text="Enter administrator password").pack() self.create_adminPass = Entry(createFrame, show="*") self.create_adminPass.pack() ## New user account widgets self.create_isAdmin = IntVar() self.create_adminCheckBox = Checkbutton(createFrame, text="Create the new account as an administrator", variable=self.create_isAdmin) self.create_adminCheckBox.pack() Label(createFrame, text="").pack() Label(createFrame, text="Enter new account's username").pack() self.create_newUser = Entry(createFrame) self.create_newUser.pack() Label(createFrame, text="Enter new account's password").pack() self.create_newPass = Entry(createFrame, show="*") self.create_newPass.pack() Label(createFrame, text="Re-enter new account's password").pack() self.create_newPass2 = Entry(createFrame, show="*") self.create_newPass2.pack() Label(createFrame, text="""\nEnter a secret question for your new account (e.g. "What is your first pet's name?") and the answer to it. This secret question will be used for resetting your password in case you forget it.\n""" , wraplength=350, justify=CENTER).pack() Label(createFrame, text="Enter new account's secret question").pack() self.create_secretQ = Entry(createFrame) self.create_secretQ.pack() Label(createFrame, text="Enter new account's secret answer").pack() self.create_secretA = Entry(createFrame) self.create_secretA.pack() self.createEntries.append(self.create_adminUser) self.createEntries.append(self.create_adminPass) self.createEntries.append(self.create_newUser) self.createEntries.append(self.create_newPass) self.createEntries.append(self.create_newPass2) self.createEntries.append(self.create_secretQ) self.createEntries.append(self.create_secretA) ## Submit button and text notifier self.create_submit = Button(createFrame, text="Register New User", command=self.submitCreateUser) self.create_submit.pack() self.create_notifier = Label(createFrame) self.create_notifier.pack() ## bind submitCreateUser to return event on last entry self.create_secretA.bind("<Return>",self.submitCreateUser) # Change password widgets changeFrame = self.notes["Change Password"] Label(changeFrame, text="Enter username").pack() self.change_user = Entry(changeFrame) self.change_user.pack() Label(changeFrame, text="Enter password").pack() self.change_oldPass = Entry(changeFrame, show="*") self.change_oldPass.pack() Label(changeFrame, text="").pack() Label(changeFrame, text="Enter new password").pack() self.change_newPass = Entry(changeFrame, show="*") self.change_newPass.pack() Label(changeFrame, text="Re-enter new password").pack() self.change_newPass2 = Entry(changeFrame, show="*") self.change_newPass2.pack() ## Submit button and text notifier Label(changeFrame, text="").pack() self.change_submit = Button(changeFrame, text="Change Password", command=self.submitChangePass) self.change_submit.pack() self.change_notifier = Label(changeFrame) self.change_notifier.pack() ## bind submitChangePass to last entry self.change_newPass2.bind("<Return>",self.submitChangePass) self.changePasswordEntries.append(self.change_user) self.changePasswordEntries.append(self.change_oldPass) self.changePasswordEntries.append(self.change_newPass) self.changePasswordEntries.append(self.change_newPass2) # Reset password widgets resetFrame = self.notes["Reset Forgotten Password"] Label(resetFrame, text="\nThis page lets you reset your account's password if you've forgotten it.\n").pack() ## Username selector newFrame = Frame(resetFrame) newFrame.pack() self.reset_userSelector = AutocompleteBox(newFrame, label="Select your username") self.reset_userSelector.initDropDown(User.listUsernames()) self.reset_userSelector.comboBox.bind('<<ComboboxSelected>>', self.handleResetUserSelect) self.reset_userSelector.pack() Label(resetFrame, text="\n").pack() self.reset_secretQ = Label(resetFrame, wraplength=350, justify=CENTER) self.reset_secretQ.pack() Label(resetFrame, text="\nEnter answer").pack() self.reset_answer = Entry(resetFrame) self.reset_answer.pack() Label(resetFrame, text="Enter new password").pack() self.reset_newPass = Entry(resetFrame, show="*") self.reset_newPass.pack() Label(resetFrame, text="Re-enter new password").pack() self.reset_newPass2 = Entry(resetFrame, show="*") self.reset_newPass2.pack() self.reset_submit = Button(resetFrame, text="Change password", command=self.submitResetPass) self.reset_submit.pack() self.reset_notifier = Label(resetFrame) self.reset_notifier.pack() self.resetPasswordEntries.append(self.reset_answer) self.resetPasswordEntries.append(self.reset_newPass) self.resetPasswordEntries.append(self.reset_newPass2)