修复了 UserPassword 不存在的问题,修复了明文密码的问题

This commit is contained in:
2026-06-18 19:02:31 +08:00
parent 5ac9c785f9
commit d769dec2ec
4 changed files with 61 additions and 15 deletions

View File

@@ -509,11 +509,12 @@ class ModifyAdminUserView(APIView):
if password:
if len(password) < 6:
return Response({'code': 400, 'msg': '密码至少6位'})
target_user.password = password
target_user.SetPassword(password)
if erjimima:
if len(erjimima) < 6:
return Response({'code': 400, 'msg': '二级密码至少6位'})
target_kefu.erjimima = erjimima # 假设二级密码也需要加密
import bcrypt as _bcrypt
target_kefu.erjimima = _bcrypt.hashpw(erjimima.encode('utf-8'), _bcrypt.gensalt(rounds=12)).decode('utf-8')
target_user.save()
target_kefu.save()
return Response({'code': 0, 'msg': '修改成功'})
@@ -602,10 +603,12 @@ class AddAdminUserView(APIView):
user_main.SetPassword(password)
user_main.save(update_fields=['UserPassword'])
# 创建客服扩展表(后台用户扩展)
import bcrypt as _bcrypt
erjimima_hashed = _bcrypt.hashpw(erjimima.encode('utf-8'), _bcrypt.gensalt(rounds=12)).decode('utf-8')
UserKefu.query.create(
user=user_main,
nicheng=nicheng,
erjimima=erjimima,
erjimima=erjimima_hashed,
zhuangtai=1
)
# 分配客服角色