コード例 #1
0
ファイル: menu.py プロジェクト: MahdiSaberi/JunkFoodShop
def Choose(choose):
    choose = int(input("Choose: "))
    with open('menu.json', 'r') as json_file:
        content = json.load(json_file)
        pairs = content.items()
        counter = 1
        for key, value in pairs:
            #print(str(counter) + ". " + "Food: "+ key," - Price: "+ value)
            if choose == counter:

                print("Your order is " + key + " with a price of " + value)
                print("1. Payoff\n2. Cancel")
                select = input()

                if select == "1":
                    pass
                elif select == "2":
                    Menu()
            if choose == 0:
                data_login = open("data_login.txt", "r")
                content = data_login.read()
                if content != "False":
                    login.login_page(username=content, password="******")
                elif content == "False":
                    options.welcome(selection="")

            counter += 1
コード例 #2
0
def login_options(user):
    print("\nHello, " + user)

    print("\n1. Menu\n2. Edit profile\n3. Logout")
    selection = 0
    try:
        selection = input()
        selection = int(selection)
    except ValueError:
        print("Please enter the correct number")
    if selection == 1:
        menu.Menu()
    if selection == 2:
        edit_profile(user)
    if selection == 3:
        print("GoodBye, " + user)
        data_login = open("data_login.txt", "w")
        data_login.write("False")
        options.welcome(selection="")
コード例 #3
0
ファイル: register.py プロジェクト: MahdiSaberi/JunkFoodShop
def register_user(user, password):

    with open('user_pass.json', 'r') as json_file:
        content = json.load(json_file)
        pairs = content.items()

    reserved = True
    while (reserved):

        user = input("Create your username: "******"This username reserved, Please create another username!")
                flag = 1
                reserved = True
                break
            elif user != key:
                if flag == 0:
                    reserved = False

    password = input("Type your password: "******"Congratulations, Your registration was successful!")
    data_login_content = open("data_login.txt", "w")
    data_login_content.write("False")
    data_login_content.close()

    str_content = str(content)
    str_content = str_content.replace(" ", "")
    str_content = str_content.replace("'", '"')
    update_contents = json.loads(str_content)
    update_contents.update(Account_set)

    with open('user_pass.json', 'w') as json_file:
        json.dump(update_contents, json_file)
    options.welcome(selection="")
コード例 #4
0
ファイル: main.py プロジェクト: MahdiSaberi/JunkFoodShop
import options

options.welcome(selection="")
コード例 #5
0
def edit_profile(user):
    print("1. Edit username\n2. Edit password")

    selection = input()
    if selection == "1":
        print("Enter new username: "******">"+user)
                if key == user:

                    with open('text.txt', 'w') as outfile:
                        json.dump(upd, outfile)

                    with open('text.txt', 'r') as file:
                        text = file.read()
                        if text.find('''"''' + new_username + '''"''' +
                                     ":") == -1:
                            text = text.replace(
                                '''"''' + user + '''"''' + ":",
                                '''"''' + new_username + '''"''' + ":")
                            print(
                                "Your username was changed successfully! Please login again"
                            )
                            data_login_content = open("data_login.txt", "w")
                            data_login_content.write("False")
                            data_login_content.close()

                        elif text.find('''"''' + new_username + '''"''' +
                                       ":") != -1:
                            print("This username was reserved!")

                    with open('text.txt', 'a') as f:
                        f.truncate(0)
                        f.write(text)

        os.remove('user_pass.json')
        os.rename(r'text.txt', r'user_pass.json')
        options.welcome(selection="")

    if selection == "2":
        print("Enter current password: "******"Your current password that you entered is wrong!")
                        break

            user_pass_data.close()

            if password_check == True:
                print("Type new password: "******">" + user)
                        if key == user and value == current_password:
                            with open('text.txt', 'w') as outfile:
                                json.dump(upd, outfile)

                            with open('text.txt', 'r') as file:
                                text = file.read()
                                text = text.replace(
                                    '''"''' + user + '''"''' + ": " + '''"''' +
                                    current_password + '''"''',
                                    '''"''' + user + '''"''' + ": " + '''"''' +
                                    new_password + '''"''')

                            with open('text.txt', 'a') as f:
                                f.truncate(0)
                                f.write(text)
                    print(
                        "Your password was changed successfully! Please login again"
                    )
                    data_login_content = open("data_login.txt", "w")
                    data_login_content.write("False")
                    data_login_content.close()

                os.remove('user_pass.json')
                os.rename(r'text.txt', r'user_pass.json')
                options.welcome(selection="")
            if password_check == False:
                edit_profile(user)