This commit is contained in:
parent
97aed41143
commit
38c0a4e3ee
|
@ -58,15 +58,19 @@ def login_required(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
async def decorated_function(*args, **kwargs):
|
async def decorated_function(*args, **kwargs):
|
||||||
info = args[1]
|
info = args[1]
|
||||||
req = info.context.get("request")
|
context = info.context
|
||||||
|
req = context.get("request")
|
||||||
authorized = await check_auth(req)
|
authorized = await check_auth(req)
|
||||||
if authorized:
|
if authorized:
|
||||||
logger.info(authorized)
|
|
||||||
user_id, user_roles = authorized
|
user_id, user_roles = authorized
|
||||||
if user_id and user_roles:
|
if user_id and isinstance(user_id, str):
|
||||||
logger.info(f" got {user_id} roles: {user_roles}")
|
context["user_id"] = user_id.strip()
|
||||||
info.context["user_id"] = user_id.strip()
|
author = get_author_by_user(user_id)
|
||||||
|
if author and "id" in author:
|
||||||
|
context["author_id"] = author["id"]
|
||||||
return await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||||
|
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
||||||
|
@ -78,15 +82,13 @@ def auth_request(f):
|
||||||
authorized = await check_auth(req)
|
authorized = await check_auth(req)
|
||||||
if authorized:
|
if authorized:
|
||||||
user_id, user_roles = authorized
|
user_id, user_roles = authorized
|
||||||
if user_id and user_roles:
|
if user_id and isinstance(user_id, str):
|
||||||
logger.info(f" got {user_id} roles: {user_roles}")
|
user_id = user_id.strip()
|
||||||
req["user_id"] = user_id.strip()
|
|
||||||
author = get_author_by_user(user_id)
|
author = get_author_by_user(user_id)
|
||||||
if author and "id" in author:
|
if author and "id" in author:
|
||||||
req["author_id"] = author["id"]
|
req["author_id"] = author["id"]
|
||||||
else:
|
else:
|
||||||
logger.debug(author)
|
logger.error('cannot find author')
|
||||||
HTTPException(status_code=404, detail="Cannot find author profile")
|
|
||||||
return await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=401, detail="Unauthorized")
|
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user