fix: 后台停用/禁用真正生效(重复集团任职与超管绕过)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-29 06:42:21 +08:00
parent fa746448cc
commit ad760a9b42
6 changed files with 137 additions and 30 deletions

View File

@@ -168,15 +168,29 @@ class KefuLoginView(APIView):
continue
password_matched = True
# 管理员:跳过二级密码和客服扩展表检查
# 管理员:跳过二级密码;但非白名单若客服已禁用仍拦截
is_admin = user.IsSuperuser or user.UserType == 'admin'
if is_admin:
from jituan.constants import SUPER_ADMIN_PHONES
is_whitelist = (user.Phone or '') in SUPER_ADMIN_PHONES
try:
kefu_probe = user.KefuProfile
except Exception:
kefu_probe = None
if kefu_probe is not None and int(getattr(kefu_probe, 'zhuangtai', 1) or 0) != 1 and not is_whitelist:
if target_user is None:
target_user = user
target_kefu = kefu_probe
continue
if is_admin or is_whitelist:
target_user = user
target_kefu = None
target_kefu = kefu_probe
break
# 客服:验证二级密码
kefu = user.KefuProfile
kefu = kefu_probe
if kefu is None:
continue
stored_erji = kefu.erjimima or ''
if stored_erji.startswith(('$2b$', '$2a$')) and len(stored_erji) == 60:
import bcrypt as _bcrypt
@@ -198,7 +212,7 @@ class KefuLoginView(APIView):
break
else:
# 循环结束未找到正常账号
if target_user and target_kefu:
if target_user and target_kefu and int(getattr(target_kefu, 'zhuangtai', 1) or 0) != 1:
# 只有被禁用的账号匹配,返回封禁提示
logger.warning(f"登录失败,客服账号已禁用: {phone}, IP: {client_ip}")
return Response({