v4.2 科目管理优化与多项修复清理
1. 科目管理:代码长度放宽至50(含数据库升级v4.2)、编辑可清空代码、重命名查重、新增 ↑↓ 快捷排序(批量重排接口)、空代码不再显示占位 2. 修复单人加减分提交空名单:showSinglePointsModal 三处重复定义收口到 points-mgmt 并共享选中状态 3. SMTP:SMTP_FROM 默认取 SMTP_USER、SMTP_ENABLED 兼容 1/yes/on、启动日志打印邮件状态、新增邮件测试接口与按钮(返回真实 SMTP 错误) 4. 密码:加密改为 bcrypt 库直连(修复 passlib 兼容问题)、重置密码不再依赖影响行数、前端统一展示422校验错误 5. 冗余清理:删除未用导入/Schema/函数、死文件 admin.js 与 sanitize.py、重复 escapeHtml、重复CSS、重复脚本加载 6. 修复11个文件被写入的 UTF-8 BOM 7. 文档与版本同步至4.2
This commit is contained in:
1 parent
990f44bf22
commit
1068bc6def
58 files changed
+366
-533
No files matched your search
@@ -83,20 +83,6 @@ async def get_connection():
|
||||
await conn.commit()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def get_transaction():
|
||||
"""获取事务连接"""
|
||||
pool = get_pool()
|
||||
async with pool.acquire() as conn:
|
||||
async with conn.cursor() as cursor:
|
||||
try:
|
||||
yield cursor
|
||||
await conn.commit()
|
||||
except Exception:
|
||||
await conn.rollback()
|
||||
raise
|
||||
|
||||
|
||||
async def execute_query(sql: str, params: tuple = None) -> List[Dict[str, Any]]:
|
||||
"""执行查询SQL"""
|
||||
async with get_connection() as cursor:
|
||||
@@ -132,19 +118,3 @@ async def execute_many(sql: str, params_list: list) -> int:
|
||||
async with get_connection() as cursor:
|
||||
await cursor.executemany(sql, params_list)
|
||||
return cursor.rowcount
|
||||
|
||||
|
||||
async def call_procedure(proc_name: str, args: tuple = None) -> List[Dict[str, Any]]:
|
||||
"""调用存储过程"""
|
||||
async with get_connection() as cursor:
|
||||
if args:
|
||||
await cursor.callproc(proc_name, args)
|
||||
else:
|
||||
await cursor.callproc(proc_name)
|
||||
|
||||
# 获取结果
|
||||
result = []
|
||||
for result_set in cursor.fetchall():
|
||||
if result_set:
|
||||
result.extend(result_set)
|
||||
return result
|
||||
@@ -9,7 +9,7 @@
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from jose import jwt, JWTError
|
||||
from jose import jwt
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from typing import Any, Optional, Dict, List
|
||||
from typing import Any
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
|
||||
@@ -54,53 +54,3 @@ def error_response(
|
||||
"data": data
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def unauthorized_response(message: str = "未授权,请重新登录") -> JSONResponse:
|
||||
"""未授权响应"""
|
||||
return JSONResponse(
|
||||
status_code=ResponseCode.UNAUTHORIZED,
|
||||
content={
|
||||
"success": False,
|
||||
"code": ResponseCode.UNAUTHORIZED,
|
||||
"message": message,
|
||||
"data": None
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def forbidden_response(message: str = "权限不足") -> JSONResponse:
|
||||
"""禁止访问响应"""
|
||||
return JSONResponse(
|
||||
status_code=ResponseCode.FORBIDDEN,
|
||||
content={
|
||||
"success": False,
|
||||
"code": ResponseCode.FORBIDDEN,
|
||||
"message": message,
|
||||
"data": None
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def not_found_response(message: str = "资源不存在") -> JSONResponse:
|
||||
"""资源不存在响应"""
|
||||
return JSONResponse(
|
||||
status_code=ResponseCode.NOT_FOUND,
|
||||
content={
|
||||
"success": False,
|
||||
"code": ResponseCode.NOT_FOUND,
|
||||
"message": message,
|
||||
"data": None
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def paginated_response(items: List[Any], total: int, page: int, page_size: int) -> Dict:
|
||||
"""分页响应数据"""
|
||||
return {
|
||||
"items": items,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": page_size,
|
||||
"total_pages": (total + page_size - 1) // page_size
|
||||
}
|
||||
@@ -15,6 +15,16 @@ import re
|
||||
from passlib.hash import bcrypt as bcrypt_hash
|
||||
from config import settings
|
||||
|
||||
try:
|
||||
import bcrypt as _bcrypt_lib
|
||||
except Exception:
|
||||
_bcrypt_lib = None
|
||||
|
||||
|
||||
def _bcrypt_bytes(password: str) -> bytes:
|
||||
"""bcrypt 仅使用前 72 字节(与历史行为一致)"""
|
||||
return password.encode('utf-8')[:72]
|
||||
|
||||
|
||||
class SecurityUtils:
|
||||
"""安全工具类"""
|
||||
@@ -35,7 +45,9 @@ class SecurityUtils:
|
||||
|
||||
@staticmethod
|
||||
def bcrypt_password(password: str) -> str:
|
||||
"""使用bcrypt加密密码"""
|
||||
"""使用bcrypt加密密码(优先使用 bcrypt 库,回退 passlib,避免版本兼容问题)"""
|
||||
if _bcrypt_lib is not None:
|
||||
return _bcrypt_lib.hashpw(_bcrypt_bytes(password), _bcrypt_lib.gensalt(rounds=12)).decode('utf-8')
|
||||
return bcrypt_hash.using(rounds=12).hash(password)
|
||||
|
||||
@staticmethod
|
||||
@@ -44,11 +56,19 @@ class SecurityUtils:
|
||||
验证密码(支持bcrypt和旧哈希)
|
||||
返回: (是否验证成功, 是否需要升级哈希)
|
||||
"""
|
||||
try:
|
||||
if bcrypt_hash.verify(plain_password, hashed_password):
|
||||
return True, False
|
||||
except Exception:
|
||||
pass
|
||||
if hashed_password and hashed_password.startswith(('$2a$', '$2b$', '$2y$')):
|
||||
if _bcrypt_lib is not None:
|
||||
try:
|
||||
if _bcrypt_lib.checkpw(_bcrypt_bytes(plain_password), hashed_password.encode('utf-8')):
|
||||
return True, False
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
if bcrypt_hash.verify(plain_password, hashed_password):
|
||||
return True, False
|
||||
except Exception:
|
||||
pass
|
||||
# 回退到旧的sha1_md5验证
|
||||
if SecurityUtils.sha1_md5_password(plain_password) == hashed_password:
|
||||
return True, True
|
||||
|
||||
Reference in new issue
Block a user