diff --git a/src/pwncore/models/user.py b/src/pwncore/models/user.py index fad8b68..d8981dc 100644 --- a/src/pwncore/models/user.py +++ b/src/pwncore/models/user.py @@ -51,7 +51,8 @@ class Team(Model): secret_hash = fields.TextField() coins = fields.IntField(default=0) points = fields.IntField(default=0) - + table_tn = fields.IntField(null=True) + members: fields.ReverseRelation[User] containers: fields.ReverseRelation[Container] diff --git a/src/pwncore/routes/team.py b/src/pwncore/routes/team.py index 6d9b0ed..a7afbd2 100644 --- a/src/pwncore/routes/team.py +++ b/src/pwncore/routes/team.py @@ -7,6 +7,7 @@ from pwncore.config import config from pwncore.models import Team, User, Team_Pydantic, User_Pydantic, Container from pwncore.routes.auth import RequireJwt +from pwncore.routes.admin import ADMIN_HASH # from pwncore.routes.leaderboard import gcache @@ -26,6 +27,9 @@ class UserAddBody(BaseModel): class UserRemoveBody(BaseModel): tag: str +class TableTNBody(BaseModel): + table_tn: int | None + @router.get("/list") async def team_list(): @@ -116,3 +120,23 @@ async def get_team_containers(response: Response, jwt: RequireJwt): ) return result + +@atomic() +@router.post("/team/{id}") +async def upsert_table_tn(id: int, data: TableTNBody, request: Request, response: Response): + admin_password = (await request.body()).strip() + + if not bcrypt.verify(admin_password, ADMIN_HASH): + response.status_code = 401 + + team = await Team.get_or_none(id=id) + if not team: + response.status_code = 404 + + try: + team.table_tn = data.table_tn + await team.save() + except Exception: + response.status_code = 500 + + return {"msg_code": "tabletn_upserted"} \ No newline at end of file