- Deploys Paper MC Minecraft Java server in offline-mode on host port 25565. - Deploys a FastAPI-based Web Admin panel on minecraft.arch-services.mywire.org (port 80/443). - Implements a layered FastAPI architecture (routers, schemas, services, database models). - Calculates deterministic version 3 Minecraft player UUIDs for player responses. - Resolves cross-container permission deadlocks by running the web container as UID 1000:1000. - Implements Write-Ahead Logging (WAL) and busy timeout to prevent SQLite concurrency lockouts. - Adds asynchronous database polling and API readiness middleware to prevent DB file initialization races. - Injects JWT_SECRET to persist administrator web sessions across restarts. - Integrates Minecraft service commands into the appctl shell management script. - Documents all containerization decisions in minecraft/adr.md.
37 lines
1.7 KiB
Python
37 lines
1.7 KiB
Python
from fastapi import APIRouter, HTTPException, Depends
|
|
from typing import List
|
|
from schemas import UserResponse, ChangePasswordRequest, ResetRequest
|
|
from services import PlayerService, ResetRequestService, get_current_user
|
|
|
|
router = APIRouter(prefix="/api", tags=["users"])
|
|
|
|
@router.get("/users", response_model=List[UserResponse])
|
|
def list_users(current_user: dict = Depends(get_current_user)):
|
|
players = PlayerService.list_all_users()
|
|
|
|
# Post-process for users who are not admins (mask email addresses)
|
|
for p in players:
|
|
if current_user["role"] != "admin" and p["username"].lower() != current_user["username"].lower():
|
|
p["email"] = "••••@••••.•••" if p.get("email") else None
|
|
|
|
return players
|
|
|
|
@router.post("/users/change-password")
|
|
def change_password(req: ChangePasswordRequest, current_user: dict = Depends(get_current_user)):
|
|
user = PlayerService.get_user_by_username(current_user["username"])
|
|
if not user or not PlayerService.AuthService.verify_password(req.old_password, user["password"]):
|
|
raise HTTPException(status_code=400, detail="Incorrect old password")
|
|
|
|
PlayerService.update_password(current_user["username"], req.new_password)
|
|
return {"message": "Password updated successfully"}
|
|
|
|
@router.post("/reset-request")
|
|
def request_password_reset(req: ResetRequest):
|
|
username = req.username.strip()
|
|
user = PlayerService.get_user_by_username(username)
|
|
if not user:
|
|
raise HTTPException(status_code=404, detail="Player username not found")
|
|
|
|
ResetRequestService.create_request(username)
|
|
return {"message": "Password reset request submitted. Please notify an administrator."}
|