1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Some more improvements, but i'm not satisfied yet

This commit is contained in:
Steffo 2020-03-09 19:13:32 +01:00
parent 68ff79f301
commit eacbb963a5
7 changed files with 17 additions and 10 deletions

View file

@ -18,6 +18,8 @@ class ApiTokenCreateStar(ApiStar):
tags = ["token"] tags = ["token"]
requires_auth = True
async def api(self, data: ApiData) -> ru.JSON: async def api(self, data: ApiData) -> ru.JSON:
user = await data.user() user = await data.user()
try: try:

View file

@ -9,6 +9,8 @@ class ApiTokenInfoStar(ApiStar):
tags = ["token"] tags = ["token"]
requires_auth = True
async def api(self, data: ApiData) -> ru.JSON: async def api(self, data: ApiData) -> ru.JSON:
token = await data.token() token = await data.token()
return token.json() return token.json()

View file

@ -9,15 +9,17 @@ from ..tables.tokens import Token
class ApiTokenPasswdStar(ApiStar): class ApiTokenPasswdStar(ApiStar):
path = "/api/token/passwd/v1" path = "/api/token/passwd/v1"
methods = ["POST"] methods = ["PUT"]
summary = "Change Royalnet password for an user." summary = "Change Royalnet password for an user."
tags = ["token"]
parameters = { parameters = {
"new_password": "The password you want to set." "new_password": "The password you want to set."
} }
tags = ["token"] requires_auth = True
async def api(self, data: ApiData) -> ru.JSON: async def api(self, data: ApiData) -> ru.JSON:
TokenT = self.alchemy.get(Token) TokenT = self.alchemy.get(Token)

View file

@ -8,12 +8,12 @@ class ApiUserFindStar(ApiStar):
summary = "Find a Royalnet user by one of their aliases." summary = "Find a Royalnet user by one of their aliases."
tags = ["user"]
parameters = { parameters = {
"alias": "One of the aliases of the user to get." "alias": "One of the aliases of the user to get."
} }
tags = ["user"]
async def api(self, data: ApiData) -> dict: async def api(self, data: ApiData) -> dict:
user = await Alias.find_user(self.alchemy, data.session, data["alias"]) user = await Alias.find_user(self.alchemy, data.session, data["alias"])
if user is None: if user is None:

View file

@ -28,16 +28,13 @@ class DocsStar(PageStar):
"paths": paths, "paths": paths,
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"LoginTokenAuth": { "RoyalnetLoginToken": {
"type": "apiKey", "type": "apiKey",
"in": "query", "in": "query",
"name": "token", "name": "token",
} }
} }
}, }
"security": [
{"LoginTokenAuth": []}
]
}) })
return HTMLResponse( return HTMLResponse(

View file

@ -19,6 +19,8 @@ class ApiStar(PageStar, ABC):
tags: List[str] = [] tags: List[str] = []
requires_auth: bool = False
async def page(self, request: Request) -> JSONResponse: async def page(self, request: Request) -> JSONResponse:
if request.query_params: if request.query_params:
data = request.query_params data = request.query_params
@ -74,4 +76,6 @@ class ApiStar(PageStar, ABC):
"type": "string" "type": "string"
} for parameter in cls.parameters] } for parameter in cls.parameters]
} }
if cls.requires_auth:
result[method.lower()]["security"] = [{"RoyalnetLoginToken": ["logged_in"]}]
return result return result

View file

@ -1 +1 @@
semantic = "5.6.1" semantic = "5.6.2"