def register(): data = json.loads(request.data) email = data['email'] username = data['name'] password = data['password'] try: app.logger.debug("Registration attempt ('%s', '%s')" % (username, email)) if (db.email_exists(email)): app.logger.debug("Registration for '%s' failed - email already taken" % email) return jsonify({"success":False, "error_message":"email already registered"}), 409 if (db.username_exists(username)): app.logger.debug("Registration for '%s' failed - username already taken" % username) return jsonify({"success":False, "error_message":"username already taken"}), 409 if (len(password) < 8): app.logger.debug("Registration for '%s' failed - password too short" % username) return jsonify({"success":False, "error_message":"password too short"}), 422 if (len(password) > 64): app.logger.debug("Registration for '%s' failed - password too long" % username) return jsonify({"success":False, "error_message":"password too long"}), 422 db.add_new_user(email, username, password) app.logger.info("Registered new user ('%s', '%s')" % (username, email)) return jsonify({"success":True}), 201 except Exception as e: app.logger.error("Error while processing registration ('%s', '%s')\n%s" % (username, email, e)) return jsonify({"success":False, "error_message":"internal server error"}), 500
def sign_up_pressed(self): self.username = self.username_entry.get() self.password = self.password_entry.get() if self.username == "" or self.password == "": messagebox.showinfo(title="Unsuccessful", message="Please fill all the entries.") else: connection = database.connect() if database.username_exists(connection, self.username): messagebox.showinfo( title="Unsuccessful", message="This username is taken. Please try another.") self.username_entry.delete(0, END) self.password_entry.delete(0, END) else: messagebox.showinfo(title="Successful", message="Done.☑") self.window.destroy()
def register(self): if not self.type_selected: tkMessageBox.showwarning("Registration Failure", "Must select if creating a " "student or teacher account.") return if (self.tpw_entry != None) and (self.tpw_entry.get() != "engineering"): tkMessageBox.showwarning( "Registration Failure", "Must enter correct password " "to create teacher account." ) return name = self.name_entry.get() username = self.username_entry.get() password = self.password_entry.get() password_conf = self.confpw_entry.get() for x in [name, username, password, password_conf]: if x == "": tkMessageBox.showwarning("Registration Failure", "Please complete all fields.") return if password != password_conf: # Pop up window saying that passwords do not match tkMessageBox.showwarning( "Registration Failure", "The passwords you have entered do not match. " "Ensure that your passwords are matching and try again.", ) return if self.type_selected == "student": account_type = "student" else: account_type = "teacher" if database.username_exists(username): tkMessageBox.showwarning( "Registration Failure", "The username that you have selected already exists. " "Please choose a different username.", ) return else: database.create_user(name, username, account_type, hasher.create_hash(password)) self.destroy() login = LoginScreen(master=self.master) login.pack()
def login(self): username = self.username_entry.get() password = self.password_entry.get() if not database.username_exists(username): tkMessageBox.showwarning( "Login Failure", "Login Failed.\nPassword " "or Username incorrect. Please try again" ) return if hasher.test_hash(password, database.get_hashedpw(username)[0][0]): self.destroy() if database.get_account_type(username) == "student": self.destroy() student_screen = student.StudentInterface(master=self.master, student=database.get_student(username)) student_screen.pack() else: self.destroy() teacher_screen = teacher.TeacherInterface(master=self.master) teacher_screen.pack() else: tkMessageBox.showwarning( "Login Failure", "Login Failed.\nPassword " "or Username incorrect. Please try again" )