associate reports with users

this will definitely need some more work.
This commit is contained in:
Jack Case
2025-10-26 16:05:20 +00:00
parent 5840b82bcc
commit 360872fdd0
2 changed files with 23 additions and 4 deletions

View File

@@ -95,15 +95,21 @@ def generate_auth_token(username):
encoded_jwt = jwt.encode(bearer_token, TOKEN_SECRET, ALGO)
return encoded_jwt
def get_token_user(decoded_token):
user = get_user(decoded_token["sub"], DB_ENGINE)
return user
def verify_auth_token(token: str):
try:
token = jwt.decode(token, TOKEN_SECRET, ALGO, audience="slopserver")
return token
except:
raise HTTPException(status_code=401, detail="invalid access token")
@app.post("/report")
async def report_slop(report: SlopReport, bearer: Annotated[str, AfterValidator(verify_auth_token), Header()]):
insert_slop(report.slop_urls, DB_ENGINE)
user = get_token_user(bearer)
insert_slop(report.slop_urls, DB_ENGINE, user)
@app.post("/check")
async def check_slop(check: Annotated[SlopReport, Body()], bearer: Annotated[str, AfterValidator(verify_auth_token), Header()]):