diff --git a/.gitignore b/.gitignore index 8ed69c1..23b6c3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ env/ app.log __pycache__/ +gunicorn.err.log +gunicorn.log +config_mysql.py diff --git a/requirements.txt b/requirements.txt index 062daeb..17f4e98 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ flask simplejson Flask-Limiter -pymysql \ No newline at end of file +pymysql +gunicorn diff --git a/velconnect/auth.py b/velconnect/auth.py index 6e135f3..9d25586 100644 --- a/velconnect/auth.py +++ b/velconnect/auth.py @@ -12,9 +12,10 @@ limiter = Limiter(key_func=get_remote_address) def require_api_key(level): def decorator(view_function): def wrapper(*args, **kwargs): + return view_function(*args, **kwargs) key = request.headers.get('x-api-key') - conn, curr = connectToDB(request) + conn, curr = connectToDB() query = """ SELECT * FROM `APIKey` WHERE `key`=%(key)s; """ diff --git a/velconnect/config_mysql.py b/velconnect/config_mysql.py deleted file mode 100644 index 4182121..0000000 --- a/velconnect/config_mysql.py +++ /dev/null @@ -1,4 +0,0 @@ -MYSQL_DATABASE_USER = 'root' -MYSQL_DATABASE_PASSWORD = 'w2e3t5t5' -MYSQL_DATABASE_HOST = 'localhost' -MYSQL_DATABASE_DB = 'vel_headset_pairing' diff --git a/velconnect/routes/api.py b/velconnect/routes/api.py index dcffae9..cf91253 100644 --- a/velconnect/routes/api.py +++ b/velconnect/routes/api.py @@ -22,7 +22,7 @@ def get_all_headsets(): return jsonify(values) -@bp.route('/pair_headset/', methods=['POST']) +@bp.route('/pair_headset/', methods=['GET']) @require_api_key(0) def pair_headset(pairing_code): conn, curr = connectToDB() @@ -32,8 +32,9 @@ def pair_headset(pairing_code): curr.execute(query, {'pairing_code': pairing_code}) values = [dict(row) for row in curr.fetchall()] curr.close() - if len(values) > 0: - return jsonify({'hw_id': values['hw_id']}) + if len(values) == 1: + print(values[0]['hw_id']) + return jsonify({'hw_id': values[0]['hw_id']}) return 'Not found', 400 @@ -62,7 +63,7 @@ def update_paring_code(): %(pairing_code)s, CURRENT_TIMESTAMP ) - ON DUPLICATE UPDATE + ON DUPLICATE KEY UPDATE pairing_code=%(pairing_code)s, last_used=CURRENT_TIMESTAMP; """