Untitled

mail@pastecode.io avatar
unknown
plain_text
10 months ago
3.9 kB
2
Indexable
Never
from time import sleep

# Add information to file
def append_new_line(file_path, new_info):
    with open(file_path, "a") as file:
        file.write(f"{new_info}, \n")

# Open and Read the file
def read_file(file_path, index):
    with open(file_path, "r") as file:
        next(file)
        get_info = []
        for line in file:
            get_info += [line.split(", ")[index].strip()]
        return get_info

# Print message
def print_message(sentence):
    print("*" * len(sentence))
    print(sentence)
    print("*" * len(sentence))

# Continue or exit
def register_confirmation():
    print("1. Login")
    print("2. Register")
    print("3. Exit")
    print("-" * 28)
    choice = input(">>> ")
    if choice == "1":
        return "Login"
    elif choice == "2":
        return "Register"
    elif choice == "3":
        return "Exit"

# Home Page
def home_page():
    print("1. Personal Information")
    print("2. View Products")
    print("3. Buy Product")
    print("4. Logout")
    home_page_choice = input(">>> ")
    if home_page_choice == "1":
        return "Personal Information"
    elif home_page_choice == "2":
        return "View Products"
    elif home_page_choice == "3":
        return "Buy Product"
    elif home_page_choice == "4":
        return "Logout"

# Personal Information
def customer_profile(customer_name):
    print(f"Name: {customer_name}")

# Check Username and Password
def name_and_password_check(input_username, input_password):
    username_checked = read_file("customer_profile.txt", 0)
    password_checked = read_file("customer_profile.txt", 1)
    if input_username in username_checked and input_password in password_checked:
        return True
    return False

# # Check Username
# def is_user_exist(input_username):
#     username_checked = read_file("customer_profile.txt", 0)
#     if input_username in username_checked:
#         return True
#     return False

# # Check Password
# def is_password_match(input_password):
#     password_checked = read_file("customer_profile.txt", 1)
#     if input_password in password_checked:
#         return True
#     return False

# Login system
# def login(input_username, input_password):
#     if is_user_exist(input_username) and is_password_match(input_password):
#         print_message(f"Welcome Back, {input_username}!")
#         return input_username
#     else:
#         print_message("This user is not found.")

def login(input_username, input_password):
    if name_and_password_check(input_username, input_password):
        print_message(f"Welcome Back, {input_username}!")
    else:
        print_message("You enter a wrong username or wrong password!")

# Register system
def registration(input_username, input_password):
        if is_user_exist(input_username):
            print_message("This username has been used!")
        else:
            append_new_line("customer_profile.txt", input_username)
            print_message(f"Thanks, {input_username}, your account has been successfully registered")

# Beginning
print_message("Welcome to Beautiful Blooms 🌺")

# Main Program
while True:
    choice = register_confirmation()
    if choice == "Login":
        login(input("Enter your name: "), input("Enter your password: "))
        home_page_choice = home_page()
        if home_page_choice == "Personal Information":
            customer_profile(customer_name)
        elif home_page_choice == "View Products":
            print("view")
        elif home_page_choice == "Buy Product":
            print("buy")
        elif home_page_choice == "Logout":
            sleep(0.5)
            print_message("Successfully Logout")
    elif choice == "Register":
        registration(input("Enter your name: "))
    elif choice == "Exit":
        print_message("See You Again!")
        break
    else:
        print_message("Invalid Input!")