def hello(): with db.auto_commit(): a = Users() b =Topic() db.session.add(b) a.email="1213s21aa2" a.password="******" db.session.add(a) return "嘻嘻嘻"
def validate_inputs(self): validators = {"empty": True, "password_match": True, "unique_email": True} # check if all fields have values all_inputs = [self.first_name_input.get(), self.last_name_input.get(), self.email_input.get(), self.address_input.get(), self.post_code_input.get(), self.city_input.get(), self.phone_no_input.get(), self.user_type.get(), self.password_input.get(), self.check_password_input.get()] for field in all_inputs: if field == "": self.error_label.config(text="Please fill all fields") validators['empty'] = False else: validators['empty'] = True # check if the passwords match if self.password_input.get() == self.check_password_input.get(): validators["password_match"] = True else: self.error_label.config(text="Passwords doesnt match") validators["password_match"] = False # check if the email is available _user = session.query(Users).filter_by(email=self.email_input.get()).first() if _user is not None: self.error_label.config(text="Email address already taken") validators['unique_email'] = False else: validators["unique_email"] = True # there is a better way to get this done but atm I'm just too tired, but as long as it works we'll be fine if validators["empty"] == True and validators["password_match"] == True and validators["unique_email"] == True: # add the user to the db new_user = Users() new_user.first_name = self.first_name_input.get() new_user.last_name = self.last_name_input.get() new_user.email = self.email_input.get() new_user.address = self.address_input.get() new_user.post_code = self.post_code_input.get() new_user.city = self.city_input.get() new_user.phone_no = self.phone_no_input.get() new_user.password = generate_password_hash(self.password_input.get(), method='sha256') if self.user_type.get() == 1: new_user.is_supplier = True else: new_user.is_supplier = False session.add(new_user) session.commit() # idk why but for some reason if you import this at the top of the file it will crash # I spent like 2 hours trying to fix this, so better don't touch it!!! from app.view.login import Login self.root.switch_frame(Login)