Skip to content

Commit

Permalink
Merge pull request #10 from tylerlight071/Features
Browse files Browse the repository at this point in the history
Major Features
  • Loading branch information
tylerlight071 authored Jan 29, 2024
2 parents 73a0b8b + 10042e1 commit 1294028
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 72 deletions.
120 changes: 64 additions & 56 deletions FurEver_Friends.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,62 +93,70 @@ def main():
if not os.path.exists(ANIMAL_DATA_FILE):
with open(ANIMAL_DATA_FILE, 'w') as animal_file:
json.dump(DEFAULT_ANIMAL_DATA, animal_file, indent=4)

while True:
print(Fore.CYAN + "\n🐕 Welcome to FurEver Friends Management System! 🐈" + Style.RESET_ALL)
print("\n1. " + Fore.GREEN + "Login" + Style.RESET_ALL)
print("2. " + Fore.YELLOW + "Exit" + Style.RESET_ALL)
choice = input("\nPlease select an option: ")

if choice == '1':
clear_screen()
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 + "🔎 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':
view_animals()
elif option == '2' and user_level >= 2:
add_animal()
elif option == '3' and user_level >= 3:
change_adopted_status()
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.")
time.sleep(2)
try:
while True:
print(Fore.CYAN + "\n🐕 Welcome to FurEver Friends Management System! 🐈" + Style.RESET_ALL)
print("\n1. " + Fore.GREEN + "Login" + Style.RESET_ALL)
print("2. " + Fore.YELLOW + "Exit" + Style.RESET_ALL)
choice = input("\nPlease select an option: ")

if choice == '1':
clear_screen()
username, user_level = login()
if username is not None:
while True:
clear_screen()

elif choice == '2':
print("\nExiting...")
time.sleep(2)
exit()
else:
print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL)
time.sleep(2)
clear_screen()
print(Fore.CYAN + "\n📖 Main Menu 📖" + 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
if user_level >= 3:
print(f"{option_counter}. " + Fore.GREEN + "🗒️ Edit animal entries" + 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':
view_animals()
elif option == '2' and user_level >= 2:
add_animal()
elif option == '3' and user_level >= 3:
change_adopted_status()
elif option == '4' and user_level >= 3:
print("\nFeature coming soon")
time.sleep(2)
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.")
time.sleep(2)
clear_screen()

elif choice == '2':
print("\nExiting...")
time.sleep(2)
exit()
else:
print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL)
time.sleep(2)
clear_screen()
except KeyboardInterrupt:
print("\nExiting...")
time.sleep(2)

if __name__ == "__main__":
main()

main()
8 changes: 7 additions & 1 deletion add_animal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def add_animal():
input(Fore.GREEN + "Press Enter to continue..."+ Style.RESET_ALL)
continue

gender = input("Enter the animal's gender: ")
if not gender.strip(): # Check if the breed is empty
print(Fore.RED + "Invalid input. Please enter the animal's name." + Style.RESET_ALL)
input(Fore.GREEN + "Press Enter to continue..."+ Style.RESET_ALL)
continue

age = input("Enter the animal's age: ")
if not age.strip(): # Check if the age is empty
print(Fore.RED + "Invalid input. Please enter the animal's name." + Style.RESET_ALL)
Expand All @@ -46,7 +52,7 @@ def add_animal():
input(Fore.GREEN + "Press Enter to continue..."+ Style.RESET_ALL)
continue

animals[name] = {'species': species, 'breed': breed, 'age': age, 'adopted': False}
animals[name] = {'name': name, 'species': species, 'breed': breed, 'gender': gender, 'age': age, 'adopted': False}
save_data(animals, ANIMAL_DATA_FILE)
print(Fore.GREEN + "\nAnimal added successfully!" + Style.RESET_ALL)
time.sleep(2)
Expand Down
10 changes: 7 additions & 3 deletions admin_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from colorama import Fore, Style
from common_functions import clear_screen, load_data, save_data
from register import register
from user_management import user_management

USER_DATA_FILE = "users.json"

Expand All @@ -10,17 +11,20 @@ def admin_dashboard():
clear_screen()
print(Fore.YELLOW + "\nADMIN Dashboard\n" + Style.RESET_ALL)
print("1. Register a new user")
print("2. Manage settings")
print("3. Logout")
print("2. User Management")
print("3. Manage settings")
print("4. Logout")
option = input("\nPlease select an option: ")

if option == '1':
register()
elif option == '2':
user_management()
elif option == '3':
# Implement settings management
print("\nThis feature is under development.")
time.sleep(2)
elif option == '3':
elif option == '4':
print("\nLogging out...")
exit()
else:
Expand Down
108 changes: 108 additions & 0 deletions user_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import time
from colorama import Fore, Style
from common_functions import clear_screen, load_data, save_data

USER_DATA_FILE = "users.json"

def user_management():
while True:
clear_screen()
print(Fore.YELLOW + "\nUser Management\n" + Style.RESET_ALL)
print("1. Change user password")
print("2. Update user information")
print("3. Delete user")
print("4. Back to admin dashboard")
option = input("\nPlease select an option: ")

if option == '1':
change_user_password()
elif option == '2':
update_user_information()
elif option == '3':
delete_user()
elif option == '4':
print("\nReturning to admin dashboard...")
time.sleep(2)
return
else:
print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL)
time.sleep(2)

def change_user_password():
users = load_data(USER_DATA_FILE)
username = input("\nEnter the username to change the password: ")

if username in users and username != "ADMIN":
new_password = input("Enter the new password: ")
users[username]['password'] = new_password
save_data(users, USER_DATA_FILE)
print(Fore.GREEN + f"\nPassword for user '{username}' changed successfully!" + Style.RESET_ALL)
elif username == "ADMIN":
print(Fore.RED + "\nYou cannot change the password for the ADMIN user." + Style.RESET_ALL)
else:
print(Fore.RED + f"\nUser '{username}' not found." + Style.RESET_ALL)

time.sleep(2)

def update_user_information():
users = load_data(USER_DATA_FILE)
clear_screen()
username = input("\nEnter the username to update information: ")

if username in users and username != "ADMIN":
clear_screen()
print("\nCurrent user information:")
print(f"\nUsername: {username}")
print(f"User Level: {users[username]['level']}")

print("\nSelect the information you want to update:")
print("\n1. Username")
print("2. User Level")
print("3. Cancel")

option = input("\nEnter your choice: ")

if option == '1':
new_username = input("Enter the new username: ")
if new_username not in users:
users[new_username] = users.pop(username)
print(Fore.GREEN + f"\nUsername updated successfully to '{new_username}'!" + Style.RESET_ALL)
else:
print(Fore.RED + f"\nUsername '{new_username}' already exists. Please choose a different username." + Style.RESET_ALL)
elif option == '2':
new_level = int(input("Enter the new user level: "))
users[username]['level'] = new_level
print(Fore.GREEN + f"\nUser level updated successfully for '{username}'!" + Style.RESET_ALL)
elif option == '3':
print("\nOperation canceled.")
else:
print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL)
elif username == "ADMIN":
print(Fore.RED + "\nYou cannot update information for the ADMIN user." + Style.RESET_ALL)
else:
print(Fore.RED + f"\nUser '{username}' not found." + Style.RESET_ALL)

save_data(users, USER_DATA_FILE)
time.sleep(2)

def delete_user():
users = load_data(USER_DATA_FILE)
username = input("\nEnter the username to delete: ")
confirm_delete = input("Are you sure you want to delete this user? (y/n) ")

if username == "ADMIN":
print("\nThe ADMIN user cannot be modified.")
time.sleep(2)
clear_screen()
else:
if username in users and confirm_delete.lower() == 'y':
del users[username]
save_data(users, USER_DATA_FILE)
print(Fore.GREEN + f"\nUser '{username}' deleted successfully!" + Style.RESET_ALL)
elif username in users and confirm_delete.lower() == 'n':
print(Fore.RED + "User has not been deleted!" + Style.RESET_ALL)
else:
print(Fore.RED + f"\nUser '{username}' not found." + Style.RESET_ALL)

time.sleep(2)

Loading

0 comments on commit 1294028

Please sign in to comment.