- 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.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from fastapi import APIRouter, Response, HTTPException, status, Depends
|
|
from schemas import LoginRequest
|
|
from services import AuthService, PlayerService, get_current_user
|
|
|
|
router = APIRouter(prefix="/api", tags=["authentication"])
|
|
|
|
@router.post("/login")
|
|
def login(login_data: LoginRequest, response: Response):
|
|
username = login_data.username.strip()
|
|
password = login_data.password
|
|
|
|
user = PlayerService.get_user_by_username(username)
|
|
|
|
# We retrieve the raw password hash from player database to verify
|
|
if not user or not AuthService.verify_password(password, user["password"]):
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid username or password")
|
|
|
|
# Generate token
|
|
token = AuthService.create_jwt_token(username)
|
|
|
|
response.set_cookie(
|
|
key="access_token",
|
|
value=token,
|
|
httponly=True,
|
|
max_age=43200, # 12 hours
|
|
samesite="lax"
|
|
)
|
|
|
|
return {"message": "Logged in successfully"}
|
|
|
|
@router.post("/logout")
|
|
def logout(response: Response):
|
|
response.delete_cookie("access_token")
|
|
return {"message": "Logged out successfully"}
|
|
|
|
@router.get("/me")
|
|
def get_me(current_user: dict = Depends(get_current_user)):
|
|
return current_user
|