Merge branch 'dev' into runny827

feat(training): 新增精益培训视频与周任务管理

# Conflicts:
#	backend/app/models/__init__.py
This commit is contained in:
runny committed 2026-09-08 18:30:09 +08:00
1 parent 85d27e9ffa
commit 91b7233872
812 files changed
+73763 -18908

No files matched your search

@@ -3,7 +3,7 @@ backend/app/services/auth/hxops/casdoor_user_sync.py
用途:集中实现 HXOPS 用户创建和改密到 Casdoor 的管理端同步。
依赖:Flask 配置、requests、HXOPS User 模型、公共 Casdoor 错误解析。
逻辑:管理端事务调用本模块;HTTP 失败映射为稳定 AppError,由上层决定回滚。
逻辑:管理端事务调用本模块;set-password 失败映射为稳定业务码(相同密码/原密码错误不用 401)。
"""
from __future__ import annotations
@@ -111,13 +111,57 @@ def raise_update_user_error(source) -> None:
)
def is_same_password_error(message: str) -> bool:
"""判断 Casdoor 是否因新密码与当前密码相同而拒绝改密。"""
text = message or ''
lowered = text.lower()
if any(
token in lowered
for token in (
'cannot be the same',
'must be different',
'same as the old',
'same as old password',
'identical to the old',
'identical to old',
'password unchanged',
'new password is the same',
)
):
return True
if 'new password' in lowered and 'old password' in lowered and 'same' in lowered:
return True
return '新密码' in text and '旧密码' in text and ('相同' in text or '一样' in text)
def raise_password_unchanged(source=None) -> None:
"""新密码与当前密码相同按业务校验失败返回,禁止使用 401 以免前端清会话。"""
data = extract_error_payload(source) if source is not None else {}
msg_text = clean_str(data.get('msg') or data.get('error_description') or data.get('message'))
raise AppError(
code='AUTH.PASSWORD_UNCHANGED',
message='New password must differ from the current password',
http_status=400,
details={'technical': msg_text[:300]} if msg_text else {},
)
def raise_set_password_error(source) -> None:
"""将 Casdoor set-password 失败映射为稳定业务错误码。"""
"""将 Casdoor set-password 失败映射为稳定业务错误码,改密业务失败不使用会话 401。"""
data = extract_error_payload(source)
msg_text = clean_str(data.get('msg') or data.get('error_description') or data.get('message'))
lowered = (msg_text or str(source or '')).lower()
raw_text = msg_text or str(source or '')
lowered = raw_text.lower()
# [STEP 1] 先识别“新密码与旧密码相同”。Casdoor 文案含 old password,若后判会被误成原密码错误 401。
if is_same_password_error(raw_text):
raise_password_unchanged(source)
# [STEP 2] 原密码错误:业务 400。401 会被前端全局 fetch 包装当成登录失效并踢回登录页。
if is_password_error(lowered) or 'old password' in lowered or 'current password' in lowered:
raise AppError(code='CASDOOR_INVALID_CREDENTIALS', message='Incorrect current password', http_status=401)
raise AppError(
code='AUTH.INCORRECT_CURRENT_PASSWORD',
message='Incorrect current password',
http_status=400,
)
if any(token in lowered for token in ('too short', 'too weak', 'password policy', 'at least')):
raise AppError(code='CASDOOR_PASSWORD_POLICY', message='New password does not meet security requirements', http_status=400)
if is_user_missing_error(lowered):