aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-11 14:28:30 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-11 14:28:30 +0100
commit709bd2fddcea033d162f61a076ec82ce34969887 (patch)
treee73a1f9d5addde981c4608482e59b67235eb9ff8 /api
parent0cb860559dce5299272b87e5e03e0a9347df27e6 (diff)
moved preferencesContext to seperate file + updatePreferences api endpoint
Diffstat (limited to 'api')
-rw-r--r--api/user/updatePreferences.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/api/user/updatePreferences.py b/api/user/updatePreferences.py
new file mode 100644
index 0000000..2eb6512
--- /dev/null
+++ b/api/user/updatePreferences.py
@@ -0,0 +1,32 @@
+from flask import Blueprint, request
+from db import cursor, connection
+from auth.login_token import token_login
+import json
+
+def format_preferences(preferences): #TODO: remove excess properties (create preferences class?)
+ return json.dumps(preferences) or ""
+
+updatePreferences = Blueprint('updatePreferences', __name__)
+
+@updatePreferences.route('/updatePreferences', methods = ['POST'])
+def index():
+ data = request.get_json()
+
+ new_preferences = data.get("newPreferences") or ""
+ token = request.cookies.get("token") or ""
+
+ if not token: return "", 401
+ login = token_login(token) or ""
+
+ if not login: return "", 403
+
+ formatted_json = format_preferences(new_preferences)
+ if not formatted_json: return "", 400
+
+ cursor.execute("update users set preferences = ? where user_id = ?", [formatted_json, login])
+ connection.commit()
+
+ return "", 200
+
+dynamic_route = ["/user", updatePreferences]
+