This commit is contained in:
parent
38c0a4e3ee
commit
63cf0b9fee
|
@ -60,15 +60,13 @@ def login_required(f):
|
||||||
info = args[1]
|
info = args[1]
|
||||||
context = info.context
|
context = info.context
|
||||||
req = context.get("request")
|
req = context.get("request")
|
||||||
authorized = await check_auth(req)
|
user_id, user_roles = await check_auth(req)
|
||||||
if authorized:
|
if user_id and isinstance(user_id, str):
|
||||||
user_id, user_roles = authorized
|
context["user_id"] = user_id.strip()
|
||||||
if user_id and isinstance(user_id, str):
|
author = get_author_by_user(user_id)
|
||||||
context["user_id"] = user_id.strip()
|
if author and "id" in author:
|
||||||
author = get_author_by_user(user_id)
|
context["author_id"] = author["id"]
|
||||||
if author and "id" in author:
|
return await f(*args, **kwargs)
|
||||||
context["author_id"] = author["id"]
|
|
||||||
return await f(*args, **kwargs)
|
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=401, detail="Unauthorized")
|
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||||
|
|
||||||
|
@ -79,16 +77,12 @@ def auth_request(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
async def decorated_function(*args, **kwargs):
|
async def decorated_function(*args, **kwargs):
|
||||||
req = args[0]
|
req = args[0]
|
||||||
authorized = await check_auth(req)
|
user_id, user_roles = await check_auth(req)
|
||||||
if authorized:
|
if user_id and isinstance(user_id, str):
|
||||||
user_id, user_roles = authorized
|
user_id = user_id.strip()
|
||||||
if user_id and isinstance(user_id, str):
|
author = get_author_by_user(user_id)
|
||||||
user_id = user_id.strip()
|
if author and "id" in author:
|
||||||
author = get_author_by_user(user_id)
|
req["author_id"] = author["id"]
|
||||||
if author and "id" in author:
|
|
||||||
req["author_id"] = author["id"]
|
|
||||||
else:
|
|
||||||
logger.error('cannot find author')
|
|
||||||
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