Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column: TableTN #61 #78

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/pwncore/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
24 changes: 24 additions & 0 deletions src/pwncore/routes/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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():
Expand Down Expand Up @@ -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"}
Loading