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