def sign_in(): var.done = True while True: print(var.color("Enter your username or email: "), end="") user_mail = input() if db.find_data("user", user_mail): index = db.find_index("user", user_mail) elif db.find_data("email", user_mail): index = db.find_index("email", user_mail) else: var.error("\nIncorrect username or email.") continue sign_pass = getpass(var.color("\nEnter your password: "******"password"] == sign_pass: acc = Accounts( db.obj(index)["user"], db.obj(index)["email"], db.obj(index)["password"], db.obj(index)["wins"], db.obj(index)["losses"], ) os.system("clear") print(var.color(f"Welcome back, {acc.user}!")) break else: var.error( "Your password doesn't match the username/email you provided.\n" )
def create(): var.done = True while not var.user_bool: print(var.color("Enter a username: "******"") new_user = input() if db.find_data("user", new_user): var.error("This username has already been taken.\n") else: var.user_bool = True while not var.email_bool: print(var.color("\nEnter a valid email: "), end="") new_email = input() if not validate_email(new_email): var.error("This email isn't valid.") else: if db.find_data("email", new_email): var.error( "This email has already been used in another account.") else: var.email_bool = True while not var.pass_bool: new_pass = getpass(var.color("\nEnter a strong password: "******"Your password isn't strong enough") continue same_pass = getpass(var.color("\nEnter the password again: ")) if same_pass != new_pass: var.error("Your password doesn't match.") else: var.pass_bool = True global acc acc = Accounts(new_user, new_email, new_pass, 0, 0) for attr in var.attribute_keys: var.attribute_values.append(getattr(acc, attr)) accdata = dict(zip(var.attribute_keys, var.attribute_values)) db.insert(accdata) print(var.color(f"\nSuccessfully made an account for {acc.user}!")) time.sleep(3.5) os.system("cls")