优化代码风格

This commit is contained in:
ZZX9599
2025-09-08 17:34:23 +08:00
parent 9b3d20511a
commit 8ceb92c572
20 changed files with 223 additions and 192 deletions

View File

@ -9,8 +9,6 @@ from passlib.context import CryptContext
from ds.config import JWT_CONFIG
from ds.db import db
# 移除这里的 from service.user_service import UserResponse 导入
# ------------------------------
# 密码加密配置
# ------------------------------
@ -23,7 +21,7 @@ SECRET_KEY = JWT_CONFIG["secret_key"]
ALGORITHM = JWT_CONFIG["algorithm"]
ACCESS_TOKEN_EXPIRE_MINUTES = int(JWT_CONFIG["access_token_expire_minutes"])
# OAuth2 依赖(从请求头获取 Token、格式Bearer <token>
# OAuth2 依赖(从请求头获取 Token、格式: Bearer <token>
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/users/login")
@ -63,7 +61,7 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -
# ------------------------------
def get_current_user(token: str = Depends(oauth2_scheme)): # 移除返回类型注解
"""从 Token 中解析用户信息、验证通过后返回当前用户"""
# 延迟导入打破循环依赖
# 延迟导入打破循环依赖
from schema.user_schema import UserResponse # 在这里导入
# 认证失败异常
@ -101,4 +99,4 @@ def get_current_user(token: str = Depends(oauth2_scheme)): # 移除返回类型
except Exception as e:
raise credentials_exception from e
finally:
db.close_connection(conn, cursor)
db.close_connection(conn, cursor)