diff --git a/FurEver_Friends.py b/FurEver_Friends.py index 9ac8f0e..397f0c6 100644 --- a/FurEver_Friends.py +++ b/FurEver_Friends.py @@ -14,7 +14,13 @@ ANIMAL_DATA_FILE = "animals.json" # Default user data if files do not exist -DEFAULT_USER_DATA = {"ADMIN": "ADMIN"} +DEFAULT_USER_DATA = { + "ADMIN": { + "password": "ADMIN", + "level": 5 + } +} + DEFAULT_ANIMAL_DATA = {} def change_admin_password(): @@ -26,7 +32,10 @@ def change_admin_password(): if new_password == confirm_password: with open(USER_DATA_FILE, 'r+') as user_file: data = json.load(user_file) - data["ADMIN"] = new_password + data["ADMIN"] = { + "password": new_password, + "level": 5 + } user_file.seek(0) json.dump(data, user_file, indent=4) user_file.truncate() @@ -49,16 +58,20 @@ def login(): users = json.load(user_file) if username in users: - if users[username] == password: + if users[username]['password'] == password: + user_level = users[username]['level'] # Retrieve the user level if username == "ADMIN" and password == "ADMIN": change_admin_password() admin_dashboard() - return username # Ensure to return after admin login + return username, user_level # Ensure to return after admin login elif username == "ADMIN": admin_dashboard() - return username + return username, user_level else: - return username # Return username for non-admin users + print("\nLogging in...") + time.sleep(2) + return username, user_level # Return username and user level for non-admin users + else: print(Fore.RED + "\nIncorrect password. Please try again." + Style.RESET_ALL) time.sleep(2) @@ -89,31 +102,44 @@ def main(): if choice == '1': clear_screen() - username = login() + username, user_level = login() if username is not None: while True: clear_screen() print(Fore.CYAN + "\nšŸ“– Main Menu šŸ“–" + Style.RESET_ALL) - print("\n1. " + Fore.GREEN + "šŸ¶ Add a new animal" + Style.RESET_ALL) - print("2. " + Fore.GREEN + "šŸ”Ž View all animals" + Style.RESET_ALL) - print("3. " + Fore.GREEN + "šŸ” Change animal adoption status" + Style.RESET_ALL) - print("4. " + Fore.YELLOW + "šŸ” Logout" + Style.RESET_ALL) + print("\n1. " + Fore.GREEN + "šŸ”Ž View all animals" + Style.RESET_ALL) + + # Initialize option counter + option_counter = 2 + + # Adjust options based on user level + if user_level >= 2: + print(f"{option_counter}. " + Fore.GREEN + "šŸ¶ Add a new animal" + Style.RESET_ALL) + option_counter += 1 + if user_level >= 3: + print(f"{option_counter}. " + Fore.GREEN + "šŸ” Change animal adoption status" + Style.RESET_ALL) + option_counter += 1 + + # Display Logout option with the correct number + print (f"{option_counter}. " + Fore.YELLOW + "šŸ” Logout" + Style.RESET_ALL) option = input("\nPlease select an option: ") if option == '1': - add_animal() - elif option == '2': view_animals() - elif option == '3': + elif option == '2' and user_level >= 2: + add_animal() + elif option == '3' and user_level >= 3: change_adopted_status() - elif option == '4': + elif option == str(option_counter) and user_level >= 1: print("\nLogging out...") + time.sleep(2) clear_screen() break else: - print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL) + print(Fore.RED + "\nInvalid option. Please try again.") time.sleep(2) clear_screen() + elif choice == '2': print("\nExiting...") time.sleep(2) @@ -125,3 +151,4 @@ def main(): if __name__ == "__main__": main() + diff --git a/change_adopted_status.py b/change_adopted_status.py index c79c84a..ac1c5b5 100644 --- a/change_adopted_status.py +++ b/change_adopted_status.py @@ -9,13 +9,17 @@ def change_adopted_status(): clear_screen() animals = load_data(ANIMAL_DATA_FILE) - name = input("\nEnter the name of the animal to mark as adopted: ") + name = input("\nEnter the name of the animal to toggle adoption status: ") if name in animals: - animals[name]['adopted'] = True + # Toggle the adopted status + animals[name]['adopted'] = not animals[name].get('adopted', False) save_data(animals, ANIMAL_DATA_FILE) - print(Fore.GREEN + f"\n{name} has been marked as adopted!" + Style.RESET_ALL) + if animals[name]['adopted']: + print(Fore.GREEN + f"\n{name} has been marked as " + Fore.CYAN + "adopted!" + Style.RESET_ALL) + else: + print(Fore.GREEN + f"\n{name} has been marked as " + Fore.RED + "not adopted!" + Style.RESET_ALL) else: print(Fore.RED + f"\nNo animal found with the name {name}" + Style.RESET_ALL) - time.sleep(2) + time.sleep(2) \ No newline at end of file diff --git a/register.py b/register.py index 16e1fb8..76006ed 100644 --- a/register.py +++ b/register.py @@ -18,12 +18,16 @@ def register(): password = getpass.getpass("Enter a password: ") confirm_password = getpass.getpass("Confirm your password: ") if password == confirm_password: - users[username] = password - save_data(users, USER_DATA_FILE) - print(Fore.GREEN + "\nRegistration successful!" + Style.RESET_ALL) - time.sleep(2) - clear_screen() - break # Exit the loop when registration is successful + user_level = input("Enter your user level (1-3): ") + if user_level.isdigit() and 1 <= int(user_level) <= 3: + users[username] = {'password': password, 'level': int(user_level)} + save_data(users, USER_DATA_FILE) + print(Fore.GREEN + "\nRegistration successful!" + Style.RESET_ALL) + time.sleep(2) + clear_screen() + break # Exit the loop when registration is successful + else: + print(Fore.RED + "\nInvalid user level. Please enter a number between 1 and 3." + Style.RESET_ALL) else: print(Fore.RED + "\nPasswords do not match. Please try again." + Style.RESET_ALL)