fix: pair code error status

This commit is contained in:
cwilvx
2024-06-21 11:50:26 +03:00
parent ae4dc77bba
commit c3472a865a
2 changed files with 12 additions and 4 deletions
+2
View File
@@ -6,6 +6,8 @@
- Rewrite stores to use dictionaries instead of list pools - Rewrite stores to use dictionaries instead of list pools
- last updated date on tracks added via watchdog is broken - last updated date on tracks added via watchdog is broken
- Disable the watchdog by default, and mark it as experimental - Disable the watchdog by default, and mark it as experimental
- rename userid to server id in config file
- Look into seeding jwts using user password + server id
# DONE # DONE
- Support auth headers - Support auth headers
+10 -4
View File
@@ -99,6 +99,7 @@ def pair_device(query: PairDeviceQuery):
Send a code to get an access token. Send an authenticated request without the code to generate a new token. Send a code to get an access token. Send an authenticated request without the code to generate a new token.
""" """
# INFO: if user is already logged in, create a new pair code
if current_user: if current_user:
token = create_new_token(get_jwt_identity()) token = create_new_token(get_jwt_identity())
key = token["accesstoken"][-6:] key = token["accesstoken"][-6:]
@@ -110,11 +111,16 @@ def pair_device(query: PairDeviceQuery):
return {"code": key} return {"code": key}
# INFO: if there's a pair code, return the token
if query.code: if query.code:
token = pair_token.get(query.code, {"msg": "Invalid code"}) token = pair_token.get(query.code, None)
pair_token = {}
return token if token:
# INFO: reset pair_token
pair_token = {}
return token
return {"msg": "Invalid code"}, 400
return {"msg": "No code provided"}, 400 return {"msg": "No code provided"}, 400
@@ -355,7 +361,7 @@ def get_all_users(query: GetAllUsersQuery):
return res return res
@api.route("/user") @api.get("/user")
def get_logged_in_user(): def get_logged_in_user():
""" """
Get logged in user Get logged in user