diff --git a/backend/app/core/auth.py b/backend/app/core/auth.py index 2fe7a71..cc205ef 100644 --- a/backend/app/core/auth.py +++ b/backend/app/core/auth.py @@ -59,10 +59,14 @@ def decode_access_token(token: str) -> Optional[dict]: def get_current_user( credentials: Optional[HTTPAuthorizationCredentials] = Depends(security), db: Session = Depends(lambda: SessionLocal()) -) -> Optional[User]: - """获取当前用户(可返回None)""" +) -> User: + """获取当前用户""" if not credentials: - return None + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="未登录", + headers={"WWW-Authenticate": "Bearer"}, + ) token = credentials.credentials payload = decode_access_token(token) @@ -84,6 +88,10 @@ def get_current_user( user = db.query(User).filter(User.f99_90_id == user_id).first() if not user: - return None + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="用户不存在", + headers={"WWW-Authenticate": "Bearer"}, + ) return user diff --git a/backend/app/routers/seek.py b/backend/app/routers/seek.py index 1ea4731..55d1967 100644 --- a/backend/app/routers/seek.py +++ b/backend/app/routers/seek.py @@ -142,10 +142,9 @@ def get_seek_list( @router.get("/stats") def get_seek_stats( - current_user = Depends(get_current_user), db: Session = Depends(get_db) ): - """获取寻配号统计""" + """获取寻配号统计(公开)""" total = db.query(SeekInfo).filter(SeekInfo.status == "active").count() matched = db.query(SeekInfo).filter(SeekInfo.is_matched == "true").count() diff --git a/backend/app/routers/users.py b/backend/app/routers/users.py index 1550661..f2fed77 100644 --- a/backend/app/routers/users.py +++ b/backend/app/routers/users.py @@ -7,7 +7,7 @@ from fastapi import APIRouter, Depends, HTTPException, status, Query, Body from sqlalchemy.orm import Session from app.core.database import get_db from app.core.auth import get_current_user -from app.models.models import User, Collection +from app.models.models import User, Collection, Information from app.schemas.schemas import UserResponse, UserUpdate router = APIRouter(prefix="/api", tags=["用户"]) diff --git a/config/CHANGELOG.md b/config/CHANGELOG.md index e896cee..13dda93 100644 --- a/config/CHANGELOG.md +++ b/config/CHANGELOG.md @@ -1,5 +1,26 @@ # 版本更新记录 +## v0.1.9 (2026-05-02) + +### 后端更新 +- **auth.py** + - 修复:get_current_user在未登录时返回None导致500错误,现在会返回401 + - 修复:用户不存在时返回None导致500错误,现在返回401 + - 修复:所有需要认证的接口现在会正确返回401 + +- **seek.py** + - 修复:/api/seek/stats接口现在不需要登录(公开接口) + +- **users.py** + - 修复:添加Information模型导入 + +### 数据库更新 +- seek_info表添加network_matched_count字段 + +### 环境配置 +- B环境短信配置:AccessKey/SignName/TemplateCode更新 +- A环境短信配置:添加短信环境变量 + ## v0.1.8 (2026-05-01) ### 前端更新 diff --git a/config/VERSION.json b/config/VERSION.json index ce1437f..ea74133 100644 --- a/config/VERSION.json +++ b/config/VERSION.json @@ -1,6 +1,6 @@ { - "version": "0.1.8", - "updated": "2026-05-01", + "version": "0.1.9", + "updated": "2026-05-02", "modules": { "frontend": { "version": "0.1.8", @@ -12,7 +12,7 @@ } }, "backend": { - "version": "0.1.8", + "version": "0.1.9", "routers": { "purchase": "0.2.0" },