fix some errors with initial pairing

dev
Anton Franzluebbers 2021-10-16 02:22:57 +00:00
parent ca462d6cd8
commit bd363e5481
5 changed files with 12 additions and 10 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
env/
app.log
__pycache__/
gunicorn.err.log
gunicorn.log
config_mysql.py

View File

@ -1,4 +1,5 @@
flask
simplejson
Flask-Limiter
pymysql
pymysql
gunicorn

View File

@ -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;
"""

View File

@ -1,4 +0,0 @@
MYSQL_DATABASE_USER = 'root'
MYSQL_DATABASE_PASSWORD = 'w2e3t5t5'
MYSQL_DATABASE_HOST = 'localhost'
MYSQL_DATABASE_DB = 'vel_headset_pairing'

View File

@ -22,7 +22,7 @@ def get_all_headsets():
return jsonify(values)
@bp.route('/pair_headset/<pairing_code>', methods=['POST'])
@bp.route('/pair_headset/<pairing_code>', 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;
"""