import random import pymongo import time from werkzeug.security import * from jobs import * from bank import * client = pymongo.MongoClient(os.getenv("MONGO_URL")) db = client.VE def create_account(name, email, password): coll = db.accounts user = coll.find_one({"email": email}) if user is not None: print("An account using that email has already been created..") return code = random.randint(000000, 999999) coll.insert_one({"_id": code, "email": email, "password": generate_password_hash(password, "scrypt"), "name": name, "account_status": "default", "job": None, "education": 1}) return code def find_account(code = None, email = None, password = None): coll = db.accounts if email is not None and password is not None: user = coll.find_one({"email": email}) user_encrypt_pass = user["password"] if user is None: print("An account with that email could not be found..") return None is_password_correct = check_password_hash(user_encrypt_pass, password) if is_password_correct is False: print("The password entered is incorrect..") return None return user['_id'] user = coll.find_one({"_id": code}) if user is None: print("That account could not be found..") return None return code def get_user_name(code): coll = db.accounts user = coll.find_one({"_id": code}) if user is None: print("The user does not have an account") return None return user['name'] def get_account_status(code): coll = db.accounts user = coll.find_one({"_id": code}) if user is None: print("The user does not have an account") return None return user['account_status'] def edit_email(code, email): coll = db.accounts user = coll.find_one({"_id": code}) if user is None: print("The user does not have an account") return None coll.update_one({"_id": code}, {"$set": {"email": email}}) return True def edit_password(code, password): coll = db.accounts user = coll.find_one({"_id": code}) if user is None: print("The user does not have an account") return None coll.update_one({"_id": code}, {"$set": {"password": generate_password_hash(password, "scrypt")}}) return True def get_user_password(code, secret_phrase): if secret_phrase != os.getenv("SECRET"): print("Operation not permitted.") time.sleep(4) return coll = db.accounts user = coll.find_one({"_id": code}) if user is None: print("The user could not be found") return return user['password'] def account_manager(code): while True: print(f""" Welcome to the account manager! Options: job - view your job if you have one. it'll also show the education requirement and the pay per hour. bank - enter a sub menu for the bank edit - edit your email or your password leave - leave the account manager """) option = input("") # begin job if option == "job": job = get_user_job(code) if job is None: print("You do not have a job at the moment") time.sleep(3) else: job_details = get_job_details(job) print(f"Job Title: {job_details.title}\n" f"Education Requirement: {job_details.education}\n" f"Pay Per Hour: {job_details.pph}") time.sleep(3) # end job # begin bank elif option == "bank": bank_status = get_bank_status(code) if bank_status is False: activate = input("Your bank account is not activated. Do you want to activate it? (y/n): ") if activate == "y": did_activate = activate_bank(code) if did_activate is True: print("You have successfully activated your bank account. You can now start getting money in your bank account") time.sleep(3) else: print("Something went wrong with activating. Try again later..") time.sleep(3) else: print("Cancelling..") time.sleep(3) option = input(f"Welcome to your bank account. What would you like to do?\n" f"deactivate - deactivate your bank account\n" f"bankrupt - declare bankruptcy\n" f"empty - clear your bank account\n" f"exit - exit the bank manager\n") if option == "deactivate": is_sure = input("Are you sure? (y/n): ") if is_sure == "y": did_deactivate = deactivate_bank(code) if did_deactivate: print("Action completed successfully") time.sleep(3) else: print("Something went wrong..") time.sleep(3) else: print("Cancelling..") time.sleep(3) elif option == "bankrupt": is_sure = input("Are you sure? (y/n): ") if is_sure == "y": did_declare_bankruptcy = declare_bankruptcy(code) if did_declare_bankruptcy is True: print("Action completed successfully") time.sleep(3) else: print("Something went wrong..") time.sleep(3) else: print("Cancelling..") time.sleep(3) elif option == "empty": is_sure = input("Are you sure? (y/n): ") if is_sure == "y": did_empty = empty_bank(code) if did_empty is True: print("Action completed successfully") time.sleep(3) else: print("Something went wrong..") time.sleep(3) else: print("Cancelling..") time.sleep(3) # end bank # begin edit elif option == "edit": option = input("What would you like to do?\n" "email - change your email\n" "password - change your password\n" "exit - leave the edit menu\n") if option == "email": email = input("Enter your new email: ") did_change_email = edit_email(code, email) if did_change_email is True: print("Action completed successfully") time.sleep(3) else: print("Something went wrong..") time.sleep(3) elif option == "password": password = input("Enter your old password: ") old_password = get_user_password(code, os.getenv("SECRET")) same_passwords = check_password_hash(old_password, password) if same_passwords is True: new_password = input("Please enter your new password: ") did_change_password = edit_password(code, new_password) if did_change_password is True: print("Action completed successfully") time.sleep(3) else: print("Something went wrong..") time.sleep(3) else: print("The passwords did not match. Cancelling operation..") time.sleep(4) # end edit # begin leave elif option == "leave": return # end leave # check if the user wants to leave the account manager leave = input("Do you want to continue editing your account? (y/n): ") if leave != "y": break