mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
add a pairing endpoint
+ append / to folder paths + filter recently played by logged in user id + fix typo in login response + update track logger migration to add foreign key
This commit is contained in:
+34
-2
@@ -48,7 +48,7 @@ def create_new_token(user: dict):
|
||||
|
||||
return {
|
||||
"msg": f"Logged in as {user['username']}",
|
||||
"acccesstoken": access_token,
|
||||
"accesstoken": access_token,
|
||||
"refreshtoken": create_refresh_token(identity=user),
|
||||
"maxage": max_age,
|
||||
}
|
||||
@@ -76,7 +76,7 @@ def login(body: LoginBody):
|
||||
return {"msg": "Hehe! invalid password"}, 401
|
||||
|
||||
res = create_new_token(user.todict())
|
||||
token = res["acccesstoken"]
|
||||
token = res["accesstoken"]
|
||||
age = res["maxage"]
|
||||
res = jsonify(res)
|
||||
set_access_cookies(res, token, max_age=age)
|
||||
@@ -84,6 +84,38 @@ def login(body: LoginBody):
|
||||
return res
|
||||
|
||||
|
||||
pair_token = dict()
|
||||
|
||||
|
||||
class PairDeviceQuery(BaseModel):
|
||||
code: str = Field("", description="The code")
|
||||
|
||||
|
||||
@api.get("/pair")
|
||||
@jwt_required(optional=True)
|
||||
def pair_device(query: PairDeviceQuery):
|
||||
"""
|
||||
Pair the Swing Music mobile app with this server
|
||||
|
||||
Send a code to get an access token. Send an authenticated request without the code to generate a new token.
|
||||
"""
|
||||
if current_user:
|
||||
token = create_new_token(get_jwt_identity())
|
||||
key = token["accesstoken"][-6:]
|
||||
|
||||
global pair_token
|
||||
pair_token = {
|
||||
key: token,
|
||||
}
|
||||
|
||||
return {"code": key}
|
||||
|
||||
if query.code:
|
||||
return pair_token.get(query.code, {"msg": "Invalid code"})
|
||||
|
||||
return {"msg": "No code provided"}, 400
|
||||
|
||||
|
||||
@api.post("/refresh")
|
||||
@jwt_required(refresh=True)
|
||||
def refresh():
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from flask_jwt_extended import current_user
|
||||
from flask_openapi3 import Tag
|
||||
from flask_openapi3 import APIBlueprint
|
||||
from pydantic import Field
|
||||
@@ -40,7 +39,6 @@ def log_track(body: LogTrackBody):
|
||||
timestamp=timestamp,
|
||||
duration=duration,
|
||||
source=source,
|
||||
userid=current_user["id"],
|
||||
)
|
||||
|
||||
return {"total entries": last_row}
|
||||
|
||||
Reference in New Issue
Block a user