Vetsi sada zmen

This commit is contained in:
Michal Kváček
2023-08-21 22:45:33 +02:00
parent 33e0a35f4b
commit 9314d31186
22 changed files with 352 additions and 201 deletions
+14 -8
View File
@@ -7,13 +7,19 @@ def public_endpoint(func):
pass
def authenticated_user_only(func):
@wraps(func)
async def decorator(*args, **kwargs):
if 'info' in kwargs:
if not kwargs['info'].context.user_id:
raise HTTPException(HTTP_401_UNAUTHORIZED, "Not authorized")
def authenticated_user_only(raise_when_unauthorized: bool = True, return_value_unauthorized=None):
def wrapper(func):
@wraps(func)
async def decorator(*args, **kwargs):
if 'info' in kwargs:
if not kwargs['info'].context.user_id:
if raise_when_unauthorized:
raise HTTPException(HTTP_401_UNAUTHORIZED, "Not authorized")
else:
return return_value_unauthorized
return await func(*args, **kwargs)
return await func(*args, **kwargs)
return decorator
return decorator
return wrapper