v0.1.9 - B环境修复:auth认证+seek统计+数据库字段+短信配置

This commit is contained in:
甲辰生产 2026-05-02 00:53:22 +08:00
parent aa10dc4cc7
commit bae5b6073a
5 changed files with 38 additions and 10 deletions

View File

@ -59,10 +59,14 @@ def decode_access_token(token: str) -> Optional[dict]:
def get_current_user( def get_current_user(
credentials: Optional[HTTPAuthorizationCredentials] = Depends(security), credentials: Optional[HTTPAuthorizationCredentials] = Depends(security),
db: Session = Depends(lambda: SessionLocal()) db: Session = Depends(lambda: SessionLocal())
) -> Optional[User]: ) -> User:
"""获取当前用户可返回None""" """获取当前用户"""
if not credentials: if not credentials:
return None raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="未登录",
headers={"WWW-Authenticate": "Bearer"},
)
token = credentials.credentials token = credentials.credentials
payload = decode_access_token(token) 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() user = db.query(User).filter(User.f99_90_id == user_id).first()
if not user: if not user:
return None raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="用户不存在",
headers={"WWW-Authenticate": "Bearer"},
)
return user return user

View File

@ -142,10 +142,9 @@ def get_seek_list(
@router.get("/stats") @router.get("/stats")
def get_seek_stats( def get_seek_stats(
current_user = Depends(get_current_user),
db: Session = Depends(get_db) db: Session = Depends(get_db)
): ):
"""获取寻配号统计""" """获取寻配号统计(公开)"""
total = db.query(SeekInfo).filter(SeekInfo.status == "active").count() total = db.query(SeekInfo).filter(SeekInfo.status == "active").count()
matched = db.query(SeekInfo).filter(SeekInfo.is_matched == "true").count() matched = db.query(SeekInfo).filter(SeekInfo.is_matched == "true").count()

View File

@ -7,7 +7,7 @@ from fastapi import APIRouter, Depends, HTTPException, status, Query, Body
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from app.core.database import get_db from app.core.database import get_db
from app.core.auth import get_current_user 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 from app.schemas.schemas import UserResponse, UserUpdate
router = APIRouter(prefix="/api", tags=["用户"]) router = APIRouter(prefix="/api", tags=["用户"])

View File

@ -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) ## v0.1.8 (2026-05-01)
### 前端更新 ### 前端更新

View File

@ -1,6 +1,6 @@
{ {
"version": "0.1.8", "version": "0.1.9",
"updated": "2026-05-01", "updated": "2026-05-02",
"modules": { "modules": {
"frontend": { "frontend": {
"version": "0.1.8", "version": "0.1.8",
@ -12,7 +12,7 @@
} }
}, },
"backend": { "backend": {
"version": "0.1.8", "version": "0.1.9",
"routers": { "routers": {
"purchase": "0.2.0" "purchase": "0.2.0"
}, },