-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added MongoDB database and linked both users and animal data to the database for better security - Converted the user password to hash - Looking into possibly converting the animal data into hash for better protection - Fully implemented audit logs - Added way for user to input their own URI link to their own database and made trigger for if to show the prompt - Minor fixes like removing the microseconds in the audit for better readability, added exit commands for certain actions and added max attempts for the login and sudo login functions. - Added credential and level validation so now if a low level user attempts to use higher command, admin is notified (via audit trail for now) - Finally added a way to edit animal entries
- Loading branch information
1 parent
268f765
commit 32f1705
Showing
12 changed files
with
563 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,5 +160,5 @@ cython_debug/ | |
#.idea/ | ||
|
||
# User Files | ||
*.json | ||
*.txt | ||
audit_log.txt | ||
config.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,49 @@ | ||
import json | ||
import os | ||
import time | ||
from colorama import Fore, Style | ||
from common_functions import clear_screen, load_data, save_data | ||
from sudo_user import sudo_user | ||
from common_functions import clear_screen, load_animal_data, save_data, log_action | ||
from pymongo import MongoClient | ||
from config import mongodb_uri | ||
|
||
ANIMAL_DATA_FILE = "animals.json" | ||
# Connect to MongoDB | ||
uri = mongodb_uri | ||
client = MongoClient(uri) | ||
|
||
db = client['animal_rescue'] | ||
animals_collection = db['animals'] | ||
|
||
def change_adopted_status(): | ||
clear_screen() | ||
|
||
# Load animal data from file | ||
animals = load_data(ANIMAL_DATA_FILE) | ||
animals = load_animal_data(animals_collection) | ||
current_user = sudo_user() | ||
|
||
name = input("\nEnter the name of the animal to toggle adoption status: ") | ||
name = input("\nEnter the name of the animal to toggle adoption status (type 'exit' to leave): ") | ||
|
||
# Check if animal exists in the data | ||
if name in animals: | ||
|
||
# Toggle the adopted status | ||
animals[name]['adopted'] = not animals[name].get('adopted', False) | ||
save_data(animals, ANIMAL_DATA_FILE) | ||
|
||
# Notify the user about the updated adoptino status | ||
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) | ||
if name == "exit": | ||
log_action(current_user, "Exited 'Change Adoption Status'") | ||
print("\nExiting...") | ||
time.sleep(2) | ||
return | ||
|
||
# Notify the user if the animal is not found | ||
else: | ||
print(Fore.RED + f"\nNo animal found with the name {name}" + Style.RESET_ALL) | ||
# Check if animal exists in the data | ||
if name in animals: | ||
|
||
# Toggle the adopted status | ||
animals[name]['adopted'] = not animals[name].get('adopted', False) | ||
save_data(animals) | ||
|
||
# Notify the user about the updated adoptino status | ||
if animals[name]['adopted']: | ||
print(Fore.GREEN + f"\n{name} has been marked as " + Fore.CYAN + "adopted!" + Style.RESET_ALL) | ||
log_action(current_user, f"{name} marked as adopted") | ||
else: | ||
print(Fore.GREEN + f"\n{name} has been marked as " + Fore.RED + "not adopted!" + Style.RESET_ALL) | ||
log_action(current_user, f"{name} marked as not adopted") | ||
# Notify the user if the animal is not found | ||
else: | ||
print(Fore.RED + f"\nNo animal found with the name {name}" + Style.RESET_ALL) | ||
|
||
time.sleep(2) | ||
time.sleep(2) |
Oops, something went wrong.