Implement the basics for account, economy, and the main file
This commit is contained in:
commit
f3db08bfaa
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.idea/
|
||||
.venv/
|
BIN
__pycache__/accounts.cpython-313.pyc
Normal file
BIN
__pycache__/accounts.cpython-313.pyc
Normal file
Binary file not shown.
BIN
__pycache__/economy.cpython-313.pyc
Normal file
BIN
__pycache__/economy.cpython-313.pyc
Normal file
Binary file not shown.
47
accounts.py
Normal file
47
accounts.py
Normal file
@ -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
|
||||
|
34
economy.py
Normal file
34
economy.py
Normal file
@ -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
|
28
main.py
Normal file
28
main.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user