Skip to content

Commit

Permalink
Rebase Branch (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlight071 authored Feb 8, 2024
2 parents d615986 + 87e343e commit 24b1b45
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 408 deletions.
157 changes: 66 additions & 91 deletions N_P_P.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import time
from sys import exit
from colorama import Fore, Style
from notifications import notifications
from staff_portal import staff_portal
from view_animals import view_animals
from common_functions import clear_screen, log_action, hash_password, get_mongodb_uri
from common_functions import clear_screen, log_action, hash_password, get_mongodb_uri, load_animal_data
from login import login
from client_database import client_database
from pymongo import MongoClient
Expand All @@ -14,6 +16,7 @@
client = MongoClient(uri)
db = client['animal_rescue']
users_collection = db['users']
animals_collection = db['animals']

# Default password
default_password = "ADMIN"
Expand All @@ -29,100 +32,72 @@
"level": 3
}

def main():
clear_screen()

try:
while True:
# Display main menu options
print(Fore.CYAN + "\n🐕 Welcome to Nexus Pet Portal! 🐈" + 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()
# Pull the username and user level from the login function
current_user, user_level = login()
if current_user is not None:
while True:
clear_screen()
# Display main menu after successful login
print(Fore.CYAN + "\n📖 Main Menu 📖" + Style.RESET_ALL)
print("\n1. " + Fore.GREEN + "🐶 Animal Database" + 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 + "🧑 Client Database" + Style.RESET_ALL)
option_counter += 1

if user_level >= 3:
print(f"{option_counter}. " + Fore.GREEN + "👤 Staff Portal" + Style.RESET_ALL)
option_counter += 1

# Display Notifications option with the correct number
notifications_option = option_counter
print(f"{option_counter}. " + Fore.GREEN + "🔔 Notifications" + Style.RESET_ALL)
option_counter += 1
def logout():
return True

logout_option = option_counter
# Display Logout option with the correct number
print (f"{option_counter}. " + Fore.YELLOW + "🔐 Logout" + Style.RESET_ALL)
option = input("\nPlease select an option: ")
# Main menu
def display_menu(options):
for i, option in enumerate(options, 1):
print(f"{i}. {option}")

# Animal Database
if option == '1':
log_action(current_user, "Entered, 'Animal Database" )
time.sleep(2)
view_animals()

# Client Database
elif option == '2' and user_level >= 2:
log_action(current_user, "Entered 'Client Database'")
time.sleep(2)
clear_screen()
client_database()


# Staff Portal
elif option == '3' and user_level == 3:
log_action(current_user, "Entered 'Staff Portal'")
print("This feature is coming soon.")
time.sleep(2)

# Notifications
elif option == str(notifications_option):
log_action(current_user, "Entered 'Notifications'")
print("This feature is coming soon.")
time.sleep(2)
def handle_option(option, functions):
try:
# Convert the option to an integer
option = int(option)
# Call the function that corresponds to the selected option
function_choice = functions[option - 1]
result = function_choice()
return result
except (IndexError, ValueError):
print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL)
time.sleep(2)

# Logout
elif option == str(logout_option):
log_action(current_user, "Logged out")
print("\nLogging out...")
time.sleep(2)
clear_screen()
break

# Invalid option
else:
print(Fore.RED + "\nInvalid option. Please try again.")
time.sleep(2)
clear_screen()
def main_menu():
options = [Fore.GREEN + "Login" + Style.RESET_ALL, Fore.YELLOW + "Exit" + Style.RESET_ALL]
functions = [login, exit]
while True:
clear_screen()
print(Fore.CYAN + "\n🐕 Welcome to Nexus Pet Portal! 🐈\n" + Style.RESET_ALL)
display_menu(options)
choice = input("\nPlease select an option: ")
user_details = handle_option(choice, functions)
if user_details is not None:
user_menu(user_details[0], user_details[1])

def user_menu(current_user, user_level):
clear_screen()
options = [Fore.GREEN + "🐶 Animal Database" + Style.RESET_ALL]
functions = [view_animals]
# Add options and functions based on user level
if user_level >= 2:
options.append(Fore.GREEN + "🧑 Client Database" + Style.RESET_ALL)
functions.append(client_database)
if user_level >= 3:
options.append(Fore.GREEN + "👤 Staff Portal" + Style.RESET_ALL)
functions.append(staff_portal)
# Add common options and functions
options.append(Fore.GREEN + "🔔 Notifications" + Style.RESET_ALL)
options.append(Fore.YELLOW + "🔐 Logout" + Style.RESET_ALL)
functions.append(notifications)
functions.append(logout)
while True:
clear_screen()
print(Fore.CYAN + "\n📖 Main Menu 📖\n" + Style.RESET_ALL)
display_menu(options)
choice = input("\nPlease select an option: ")
# Logout option
if choice == str(len(options)):
log_action(current_user, "Logged out")
print("\nLogging out...")
time.sleep(2)
clear_screen()
break
handle_option(choice, functions)

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()

def main():
clear_screen()
try:
main_menu()
except KeyboardInterrupt:
print("\n\nExiting...")
time.sleep(2)
Expand Down
7 changes: 4 additions & 3 deletions add_animal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
from colorama import Fore, Style
from common_functions import clear_screen, log_action, get_mongodb_uri, load_animal_data
from sudo_user import sudo_user
from sudo_user_login import SudoUser
from tables import print_animal_table
from pymongo import MongoClient

Expand All @@ -11,6 +11,7 @@

db = client['animal_rescue']
animals_collection = db['animals']
users_collection = db['users']

def add_animal():

Expand All @@ -20,7 +21,7 @@ def add_animal():
while True:
clear_screen()

sudo_user()
SudoUser(users_collection.database).login()

# Display header
print(Fore.CYAN + "\n🐾 Add Animal 🐾\n" + Style.RESET_ALL)
Expand Down Expand Up @@ -65,7 +66,7 @@ def add_animal():

clear_screen()
# Make the user verify their identity
current_user = sudo_user()
current_user = SudoUser(users_collection.database).login()

# Add hashed animal data to the animals collection
animals_collection.insert_one ({
Expand Down
30 changes: 20 additions & 10 deletions client_database.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import time
from sudo_user import sudo_user
from sudo_user_login import SudoUser
from colorama import Fore, Style
from common_functions import clear_screen
from common_functions import clear_screen, get_mongodb_uri
from customer_adoption_form_dog import adopt_dog_form
from pymongo import MongoClient

# Connect to MongoDB
uri = get_mongodb_uri()
client = MongoClient(uri)

db = client['animal_rescue']
animals_collection = db['animals']
users_collection = db['users']

new_feature_message = "\nThis feature is coming soon."

def modify_clint_database():
clear_screen()
Expand Down Expand Up @@ -30,7 +41,7 @@ def modify_clint_database():
adopt_dog_form()

elif adoption_form == 'cats':
print("\nThis feature is coming soon.")
print(new_feature_message)
time.sleep(2)
clear_screen()

Expand All @@ -40,15 +51,15 @@ def modify_clint_database():
clear_screen()

elif choice == '3':
print("\nThis feature is coming soon.")
print(new_feature_message)
time.sleep(2)
clear_screen()

elif choice == '4':
print("\nExiting Modify Database...")
time.sleep(1)
clear_screen()
return


else:
print(Fore.RED + "Invalid input. Please try again." + Style.RESET_ALL)
Expand All @@ -60,7 +71,7 @@ def client_database():

clear_screen()

sudo_user()
SudoUser(users_collection.database).login()

print(Fore.CYAN + "\n🧑 Client Database 🧑" + Style.RESET_ALL)
print("\n1. " + Fore.GREEN + "🔍 Search" + Style.RESET_ALL)
Expand All @@ -70,7 +81,7 @@ def client_database():
choice = input("\nPlease select an option: ")

if choice == '1':
print("This feature is coming soon.")
print(new_feature_message)
time.sleep(2)
clear_screen()

Expand All @@ -80,15 +91,14 @@ def client_database():
modify_clint_database()

elif choice == '3':
print("This feature is coming soon.")
time.sleep(2)
print(new_feature_message)
time.sleep(1)
clear_screen()

elif choice == '4':
print("Exiting Client Database...")
time.sleep(1)
clear_screen()
return

else:
print(Fore.RED + "\nInvalid input. Please try again." + Style.RESET_ALL)
Expand Down
5 changes: 3 additions & 2 deletions edit_animal_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from tables import print_animal_table
from colorama import Fore, Style
from pymongo import MongoClient
from sudo_user import sudo_user
from sudo_user_login import SudoUser

# Connect to MongoDB
uri = get_mongodb_uri()
client = MongoClient(uri)

db = client['animal_rescue']
animals_collection = db['animals']
users_collection = db['users']

FIELDS = {
1: "name",
Expand Down Expand Up @@ -46,7 +47,7 @@ def modify_animal():
animals = load_animal_data(animals_collection)

clear_screen()
sudo_user()
SudoUser(users_collection.database).login()
print(Fore.CYAN + "\n🐾 Modify Animal 🐾\n" + Style.RESET_ALL)

animal_name = get_animal_name()
Expand Down
7 changes: 3 additions & 4 deletions login.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def change_admin_password(username):
clear_screen()
print(Fore.RED + "\nPassword cannot be empty. Please try again." + Style.RESET_ALL)
continue
else:
break
break

confirm_password = getpass.getpass("Confirm the new password: ")

Expand Down Expand Up @@ -71,8 +70,7 @@ def reset_password(username):
clear_screen()
print(Fore.RED + "\nPassword cannot be empty. Please try again." + Style.RESET_ALL)
continue
else:
break
break

confirm_password = getpass.getpass("Confirm the new password: ")

Expand All @@ -98,6 +96,7 @@ def reset_password(username):
reset_password(username)

def login():
clear_screen()
attempts = 0
# Continuous loop for login
while attempts < MAX_ATTEMPTS:
Expand Down
5 changes: 5 additions & 0 deletions notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import time

def notifications():
print("\nThis is the notifications feature. It is currently under construction. Please come back later.")
time.sleep(2)
5 changes: 5 additions & 0 deletions staff_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import time

def staff_portal():
print("\nThis is the staff portal. It is currently under construction. Please come back later.")
time.sleep(2)
Loading

0 comments on commit 24b1b45

Please sign in to comment.