新增小程序后端代码,包括数据库、路由、服务层等。

小程序前后端打通,包括登录、注册、绑定设备、查询绑定信息,修改小朋友名称等功能。
This commit is contained in:
HycJack
2026-04-13 01:54:57 +08:00
parent 33715373b0
commit a22fcafea9
46 changed files with 3713 additions and 268 deletions

View File

@@ -14,7 +14,7 @@ except ModuleNotFoundError:
from security import auth_error_response, decode_access_token
EXCLUDED_PATH_PREFIXES = (
NO_AUTH_PATH_PREFIXES = (
"/health",
"/docs",
"/redoc",
@@ -22,11 +22,22 @@ EXCLUDED_PATH_PREFIXES = (
"/auth/login",
)
logger = logging.getLogger("app.auth")
def _is_no_auth_path(path: str) -> bool:
for prefix in NO_AUTH_PATH_PREFIXES:
if path == prefix or path.startswith(f"{prefix}/"):
return True
return False
def _is_excluded_path(path: str) -> bool:
for prefix in EXCLUDED_PATH_PREFIXES:
return _is_no_auth_path(path)
logger = logging.getLogger("app.auth")
def _is_no_auth_path(path: str) -> bool:
for prefix in NO_AUTH_PATH_PREFIXES:
if path == prefix or path.startswith(f"{prefix}/"):
return True
return False
@@ -39,7 +50,7 @@ def install_auth_middleware(app: FastAPI) -> None:
call_next: Callable[[Request], Awaitable],
):
path = request.url.path
if request.method == "OPTIONS" or _is_excluded_path(path):
if request.method == "OPTIONS" or _is_no_auth_path(path):
return await call_next(request)
auth_header = request.headers.get("Authorization")
@@ -87,9 +98,9 @@ def install_auth_middleware(app: FastAPI) -> None:
db.execute(
text(
"""
SELECT id, status
FROM chat_user
WHERE id = :user_id
SELECT user_id, status
FROM parents
WHERE user_id = :user_id
LIMIT 1
"""
),