Skip to content

Commit

Permalink
Merge pull request #8 from tylerlight071/Features
Browse files Browse the repository at this point in the history
User Levels
  • Loading branch information
tylerlight071 authored Jan 29, 2024
2 parents b42f597 + 8285d36 commit 73a0b8b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 26 deletions.
59 changes: 43 additions & 16 deletions FurEver_Friends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -125,3 +151,4 @@ def main():

if __name__ == "__main__":
main()

12 changes: 8 additions & 4 deletions change_adopted_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 10 additions & 6 deletions register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 73a0b8b

Please sign in to comment.