test/custom-admin-ui #3
@@ -85,6 +85,18 @@ def _require_admin_payload(authorization: str) -> dict:
|
|||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
|
||||||
|
def get_admin_session(authorization: str = Header(default=None)) -> dict:
|
||||||
|
token = _extract_bearer_token(authorization)
|
||||||
|
payload = _require_admin_payload(authorization)
|
||||||
|
return {
|
||||||
|
"id": "admin",
|
||||||
|
"username": "admin",
|
||||||
|
"token": token,
|
||||||
|
"token_type": "Bearer",
|
||||||
|
"expires_at": payload.get("exp"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ADMIN_PUBLIC_ENDPOINTS = {("POST", "/admin/login")}
|
ADMIN_PUBLIC_ENDPOINTS = {("POST", "/admin/login")}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from fastapi import APIRouter, Depends, HTTPException
|
|||||||
from apps.admin.services import FileService, ConfigService, LocalFileService
|
from apps.admin.services import FileService, ConfigService, LocalFileService
|
||||||
from apps.admin.dependencies import (
|
from apps.admin.dependencies import (
|
||||||
admin_required,
|
admin_required,
|
||||||
|
get_admin_session,
|
||||||
get_file_service,
|
get_file_service,
|
||||||
get_config_service,
|
get_config_service,
|
||||||
get_local_file_service,
|
get_local_file_service,
|
||||||
@@ -33,6 +34,16 @@ async def login(data: LoginData):
|
|||||||
return APIResponse(detail={"token": token, "token_type": "Bearer"})
|
return APIResponse(detail={"token": token, "token_type": "Bearer"})
|
||||||
|
|
||||||
|
|
||||||
|
@admin_api.get("/verify")
|
||||||
|
async def verify_admin(session: dict = Depends(get_admin_session)):
|
||||||
|
return APIResponse(detail=session)
|
||||||
|
|
||||||
|
|
||||||
|
@admin_api.post("/logout")
|
||||||
|
async def logout_admin():
|
||||||
|
return APIResponse(detail={"ok": True})
|
||||||
|
|
||||||
|
|
||||||
@admin_api.get("/dashboard")
|
@admin_api.get("/dashboard")
|
||||||
async def dashboard():
|
async def dashboard():
|
||||||
all_codes = await FileCodes.all()
|
all_codes = await FileCodes.all()
|
||||||
|
|||||||
Reference in New Issue
Block a user