This commit is contained in:
parent
63cf0b9fee
commit
12c5d2677d
|
@ -3,6 +3,7 @@
|
||||||
- auth logix synced with core
|
- auth logix synced with core
|
||||||
- added httpx
|
- added httpx
|
||||||
- aiohttp and requests removed
|
- aiohttp and requests removed
|
||||||
|
- core adapter loads data from redis now
|
||||||
|
|
||||||
[0.3.1]
|
[0.3.1]
|
||||||
- glitchtip connect
|
- glitchtip connect
|
||||||
|
|
|
@ -63,7 +63,7 @@ def login_required(f):
|
||||||
user_id, user_roles = await check_auth(req)
|
user_id, user_roles = await check_auth(req)
|
||||||
if user_id and isinstance(user_id, str):
|
if user_id and isinstance(user_id, str):
|
||||||
context["user_id"] = user_id.strip()
|
context["user_id"] = user_id.strip()
|
||||||
author = get_author_by_user(user_id)
|
author = await get_author_by_user(user_id)
|
||||||
if author and "id" in author:
|
if author and "id" in author:
|
||||||
context["author_id"] = author["id"]
|
context["author_id"] = author["id"]
|
||||||
return await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
|
@ -80,7 +80,7 @@ def auth_request(f):
|
||||||
user_id, user_roles = await check_auth(req)
|
user_id, user_roles = await check_auth(req)
|
||||||
if user_id and isinstance(user_id, str):
|
if user_id and isinstance(user_id, str):
|
||||||
user_id = user_id.strip()
|
user_id = user_id.strip()
|
||||||
author = get_author_by_user(user_id)
|
author = await 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"]
|
||||||
return await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
|
|
|
@ -10,33 +10,33 @@ from services.rediscache import redis
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
def get_all_authors():
|
async def get_all_authors():
|
||||||
authors = []
|
authors = []
|
||||||
redis_key = "user:*"
|
redis_key = "user:*"
|
||||||
|
|
||||||
result = redis.execute("GET", redis_key)
|
result = await redis.execute("GET", redis_key)
|
||||||
if isinstance(result, str):
|
if isinstance(result, str):
|
||||||
authors = json.loads(result)
|
authors = json.loads(result)
|
||||||
|
|
||||||
return authors
|
return authors
|
||||||
|
|
||||||
|
|
||||||
def get_author_by_user(user: str):
|
async def get_author_by_user(user: str):
|
||||||
author = None
|
author = None
|
||||||
redis_key = f"user:{user}"
|
redis_key = f"user:{user}"
|
||||||
|
|
||||||
result = redis.execute("GET", redis_key)
|
result = await redis.execute("GET", redis_key)
|
||||||
if isinstance(result, str):
|
if isinstance(result, str):
|
||||||
author = json.loads(result)
|
author = json.loads(result)
|
||||||
|
|
||||||
return author
|
return author
|
||||||
|
|
||||||
|
|
||||||
def get_author_followed(author_id: int):
|
async def get_author_followed(author_id: int):
|
||||||
authors = []
|
authors = []
|
||||||
redis_key = f"author:{author_id}:follows-authors"
|
redis_key = f"author:{author_id}:follows-authors"
|
||||||
|
|
||||||
result = redis.execute("GET", redis_key)
|
result = await redis.execute("GET", redis_key)
|
||||||
if isinstance(result, str):
|
if isinstance(result, str):
|
||||||
authors = json.loads(result)
|
authors = json.loads(result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user