commit f3db08bfaa126f778cb358adee5a3e00d9f86b45 Author: TropiiDev Date: Sun Jan 5 01:43:53 2025 -0500 Implement the basics for account, economy, and the main file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e8ecb4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +.venv/ \ No newline at end of file diff --git a/__pycache__/accounts.cpython-313.pyc b/__pycache__/accounts.cpython-313.pyc new file mode 100644 index 0000000..4991a26 Binary files /dev/null and b/__pycache__/accounts.cpython-313.pyc differ diff --git a/__pycache__/economy.cpython-313.pyc b/__pycache__/economy.cpython-313.pyc new file mode 100644 index 0000000..e94fad4 Binary files /dev/null and b/__pycache__/economy.cpython-313.pyc differ diff --git a/accounts.py b/accounts.py new file mode 100644 index 0000000..4bf43f3 --- /dev/null +++ b/accounts.py @@ -0,0 +1,47 @@ +import pymongo +import random +from werkzeug.security import * + +client = pymongo.MongoClient("mongodb://192.168.86.221:27017/") +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}) + + 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 + diff --git a/economy.py b/economy.py new file mode 100644 index 0000000..2626352 --- /dev/null +++ b/economy.py @@ -0,0 +1,34 @@ +import pymongo +import random + +from accounts import * + +client = pymongo.MongoClient("mongodb://192.168.86.221:27017/") +db = client.VE + +def get_balance(code): + coll = db.economy + user = coll.find_one({"account_id": code}) + + if user is None: + did_create = create_econ_account(code) + if did_create is False: + print("Something went wrong...") + return + + user = coll.find_one({"account_id": code}) + return user['balance'] + + return user['balance'] + +def create_econ_account(code): + coll = db.economy + user = coll.find_one({"account_id": code}) + + if user is not None: + print("User already has an account") + return False + + coll.insert_one({"_id": random.randint(000000, 999999), "account_id": code, "balance": 0}) + + return True diff --git a/main.py b/main.py new file mode 100644 index 0000000..91f238e --- /dev/null +++ b/main.py @@ -0,0 +1,28 @@ +from dotenv import load_dotenv +load_dotenv() + +from accounts import * +from economy import * + +code = None + +does_user_have_account = input("Do you have an account? (y/n): ") + +if does_user_have_account == "y": + email = input("Please enter your email: ") + password = input("Please enter your password: ") + + code = find_account(code = None, email=email, password=password) +elif does_user_have_account == "n": + email = input("Please enter your email: ") + password = input("Please enter your password: ") + name = input("Please enter your name: ") + + code = create_account(name, email, password) +else: + print("That is not a valid answer") + +while code is not None: + balance = get_balance(code) + print(f"Welcome to your bank account.\nBalance: {balance}") + break \ No newline at end of file