优化代码风格
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user