Compare commits

..

4 Commits

Author SHA1 Message Date
cc3a6ab0c7 fix: 修复认证 422 错误和生产环境部署配置
All checks were successful
continuous-integration/drone/push Build is passing
- HTTPBearer 使用 auto_error=False 避免 422 错误
- 生产环境使用与测试相同的数据库密钥配置
2026-01-24 17:43:21 +08:00
aa3f5f6108 fix: 修复 HTTPBearer 返回 422 错误的问题
All checks were successful
continuous-integration/drone/push Build is passing
- 设置 HTTPBearer(auto_error=False) 避免验证错误
- 在 get_current_user 中手动检查并返回 401
2026-01-24 17:39:04 +08:00
9ff89f4a7d fix: 修复日志查询接口访问不存在字段的问题
All checks were successful
continuous-integration/drone/push Build is passing
- ip_address 从 context.ip 获取
- 移除不存在的 extra_data 字段
- 修复 CSV/Excel 导出中的同样问题
2026-01-24 17:25:17 +08:00
b04ee51020 chore: 触发 CI/CD 部署
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-24 17:18:53 +08:00
3 changed files with 24 additions and 13 deletions

View File

@@ -71,7 +71,7 @@ steps:
branch:
- develop
# 部署生产环境
# 部署生产环境(使用与测试相同的数据库配置)
- name: deploy-prod
image: docker:dind
volumes:
@@ -79,13 +79,13 @@ steps:
path: /var/run/docker.sock
environment:
DATABASE_URL:
from_secret: database_url_prod
from_secret: database_url
API_KEY:
from_secret: api_key_prod
from_secret: api_key
JWT_SECRET:
from_secret: jwt_secret_prod
from_secret: jwt_secret
CONFIG_ENCRYPT_KEY:
from_secret: config_encrypt_key_prod
from_secret: config_encrypt_key
commands:
- docker network create platform-network-prod 2>/dev/null || true
- docker stop platform-backend-prod platform-frontend-prod || true

View File

@@ -22,7 +22,7 @@ from ..models.tenant_app import TenantApp
from ..models.tenant_wechat_app import TenantWechatApp
router = APIRouter(prefix="/auth", tags=["认证"])
security = HTTPBearer()
security = HTTPBearer(auto_error=False)
class LoginRequest(BaseModel):
@@ -48,24 +48,33 @@ class ChangePasswordRequest(BaseModel):
# 权限依赖
async def get_current_user(
credentials: HTTPAuthorizationCredentials = Depends(security),
credentials: Optional[HTTPAuthorizationCredentials] = Depends(security),
db: Session = Depends(get_db)
) -> User:
"""获取当前用户"""
if not credentials:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="需要登录认证",
headers={"WWW-Authenticate": "Bearer"}
)
token = credentials.credentials
token_data = decode_token(token)
if not token_data:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Token 无效或已过期"
detail="Token 无效或已过期",
headers={"WWW-Authenticate": "Bearer"}
)
user = db.query(User).filter(User.id == token_data.user_id).first()
if not user or user.status != 1:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="用户不存在或已禁用"
detail="用户不存在或已禁用",
headers={"WWW-Authenticate": "Bearer"}
)
return user

View File

@@ -117,8 +117,8 @@ async def query_logs(
"method": item.method,
"status_code": item.status_code,
"duration_ms": item.duration_ms,
"ip_address": item.ip_address,
"extra_data": item.extra_data,
"ip_address": item.context.get("ip") if item.context else None,
"context": item.context,
"stack_trace": item.stack_trace,
"log_time": str(item.log_time) if item.log_time else None
}
@@ -182,6 +182,7 @@ def export_csv(logs: list) -> StreamingResponse:
# 写入数据
for log in logs:
ip_address = log.context.get("ip") if log.context else ""
writer.writerow([
log.id,
log.log_type,
@@ -194,7 +195,7 @@ def export_csv(logs: list) -> StreamingResponse:
log.method or "",
log.status_code or "",
log.duration_ms or "",
log.ip_address or "",
ip_address or "",
str(log.log_time) if log.log_time else ""
])
@@ -242,6 +243,7 @@ def export_excel(logs: list) -> StreamingResponse:
# 写入数据
for row, log in enumerate(logs, 2):
ip_address = log.context.get("ip") if log.context else ""
ws.cell(row=row, column=1, value=log.id)
ws.cell(row=row, column=2, value=log.log_type)
ws.cell(row=row, column=3, value=log.level)
@@ -253,7 +255,7 @@ def export_excel(logs: list) -> StreamingResponse:
ws.cell(row=row, column=9, value=log.method or "")
ws.cell(row=row, column=10, value=log.status_code or "")
ws.cell(row=row, column=11, value=log.duration_ms or "")
ws.cell(row=row, column=12, value=log.ip_address or "")
ws.cell(row=row, column=12, value=ip_address or "")
ws.cell(row=row, column=13, value=str(log.log_time) if log.log_time else "")
# 调整列宽