diff --git a/Options.ini b/Options.ini index 3483e31..518582d 100644 --- a/Options.ini +++ b/Options.ini @@ -1,13 +1,13 @@ [DEFAULT] -host = 'http://0.0.0.0:5000' +host = http://0.0.0.0:5000 max_desks = 8 [SETTINGS] lockqrcode_whit_secret = True user = Admin -path_json_settings = '/Server/json/availiable-products.json' +path_json_settings = ./Server/json/availiable-products.json [OTHER] log_diagnose = True -first_startup = False +first_startup = True diff --git a/README.md b/README.md index 5371008..19ae1d2 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Default has to be changed to your needs: host -> is where the QR code points to whit secret if enabled. max_desks -> How many desk it shoud create. -Execute in Terminal the "pip install -r required.txt" to download depending and "python app.py" to run the Flask server and whit it the webserver. +Execute in Terminal "python3 -m venv .venv", for the virtual enviroment activate it whit "source .venv/bin/acitvate" (Linux) " or ".venv/Scripts/activate.bat" (Windows) and then "pip install -r required.txt" to download depending and "python app.py" to run the Flask server and whit it the webserver. ## diff --git a/Server/DB/querys.py b/Server/DB/querys.py index e60f879..a42532f 100644 --- a/Server/DB/querys.py +++ b/Server/DB/querys.py @@ -2,9 +2,15 @@ from loguru import logger import json import bcrypt +import configparser from Server.DB.handler import QR, Product, Order, session, User +config = configparser.ConfigParser() +config.sections() +config.read('Options.ini') + + class compare: def is_user_pass_valid(username, password): session_username = session.query(User).filter(User.username == username).one() @@ -102,19 +108,20 @@ class get: return False ''' def valid_products(get_json_=False): - with open(config['SETTINGS']['path_json_settings'], 'r') as file: - #Parse Json Product List - products = json.load(file) - if get_json_: - return products - else: - valide_products = [] - for category in products.get('products'): - for product in products.get('products').get(category): - print(product) - if int(product['quantity']) >= 0: - valide_products.append(product['name']) - return valide_products + global config + with open(config['SETTINGS']['path_json_settings'], 'r') as file: + #Parse Json Product List + products = json.load(file) + if get_json_: + return products + else: + valide_products = [] + for category in products.get('products'): + for product in products.get('products').get(category): + print(product) + if int(product['quantity']) >= 0: + valide_products.append(product['name']) + return valide_products def all_orders(): # All unfinished orders (finished is False or string "False") diff --git a/Server/Host/flaskApp.py b/Server/Host/flaskApp.py index dc924b0..0b22e59 100644 --- a/Server/Host/flaskApp.py +++ b/Server/Host/flaskApp.py @@ -37,7 +37,7 @@ login_manager.init_app(app) if config['OTHER']['first_startup'] == 'True': print("Please enter a Secure Admin Password:") - add._create_user('Admin',input()) + add._create_user(config['SETTINGS']['user'],input()) config.set('OTHER', 'first_startup', 'False') with open('Options.ini', 'w') as configfile: config.write(configfile) @@ -112,9 +112,9 @@ def orders(): #TODO on new orderGet refresh orders list @app.route("/order_get", methods=['GET','POST']) def order_get(): desk= 1 - + global config #POST order - if request.method == 'POST' and config['SETTINGS']['lockqrcode_whit_secret'] == True: + if request.method == 'POST' and config['SETTINGS']['lockqrcode_whit_secret'] == 'True': ordered_list = [] desk = request.form['desk'] form = request.form @@ -133,18 +133,17 @@ def order_get(): elif request.method == 'GET': desk = int(request.args['desk']) secret = int(request.args['secret']) - try:#TODO FIX! #Feature = True #TODO:Encryption Salting hasing and anti rainbow attack for qr code?? (needed?) - if config['SETTINGS']['lockqrcode_whit_secret'] and compare.is_QRSecret_valid(desk,secret): - return render_template('index.html', desk=desk, MAX_DESKS=config['DEFAULT']['max_desks'], orderableItems = get.valid_products(get_json_=True)) - elif config['SETTINGS']['lockqrcode_whit_secret'] == False: - return render_template('index.html', desk=desk, MAX_DESKS=config['DEFAULT']['max_desks'],orderableItems = get.valid_products(get_json_=True)) - return '