修复了 User Password 验权
This commit is contained in:
@@ -598,8 +598,9 @@ class AddAdminUserView(APIView):
|
|||||||
UserName=openid,
|
UserName=openid,
|
||||||
OpenID=openid,
|
OpenID=openid,
|
||||||
Phone=phone,
|
Phone=phone,
|
||||||
UserPassword=password,
|
|
||||||
)
|
)
|
||||||
|
user_main.SetPassword(password)
|
||||||
|
user_main.save(update_fields=['UserPassword'])
|
||||||
# 创建客服扩展表(后台用户扩展)
|
# 创建客服扩展表(后台用户扩展)
|
||||||
UserKefu.query.create(
|
UserKefu.query.create(
|
||||||
user=user_main,
|
user=user_main,
|
||||||
|
|||||||
@@ -2312,10 +2312,9 @@ class AdminLoginView(APIView):
|
|||||||
# 3. 使用事务确保数据一致性
|
# 3. 使用事务确保数据一致性
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# 【优化点1】使用select_related一次性获取管理员扩展表
|
# 【优化点1】使用select_related一次性获取管理员扩展表
|
||||||
# 只查询管理员类型的用户
|
# 只查询管理员类型的用户(密码用 CheckPassword 验证,不能在 ORM 中直接匹配哈希)
|
||||||
user = User.query.filter(
|
user = User.query.filter(
|
||||||
Phone=zhanghao, # 手机号作为账号
|
Phone=zhanghao, # 手机号作为账号
|
||||||
UserPassword=mima, # 密码
|
|
||||||
admin_profile__isnull=False # 必须是管理员类型
|
admin_profile__isnull=False # 必须是管理员类型
|
||||||
).select_related('admin_profile').first()
|
).select_related('admin_profile').first()
|
||||||
|
|
||||||
@@ -2326,6 +2325,13 @@ class AdminLoginView(APIView):
|
|||||||
status=status.HTTP_401_UNAUTHORIZED
|
status=status.HTTP_401_UNAUTHORIZED
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 验证密码(bcrypt 哈希验证)
|
||||||
|
if not user.CheckPassword(mima):
|
||||||
|
return Response(
|
||||||
|
{'code': 401, 'msg': '登录失败', 'data': None},
|
||||||
|
status=status.HTTP_401_UNAUTHORIZED
|
||||||
|
)
|
||||||
|
|
||||||
# 【优化点2】检查管理员扩展表是否存在
|
# 【优化点2】检查管理员扩展表是否存在
|
||||||
if not hasattr(user, 'admin_profile'):
|
if not hasattr(user, 'admin_profile'):
|
||||||
return Response(
|
return Response(
|
||||||
@@ -6747,8 +6753,8 @@ class KefuLoginView(APIView):
|
|||||||
|
|
||||||
for user in user_mains:
|
for user in user_mains:
|
||||||
kefu = user.kefu_profile
|
kefu = user.kefu_profile
|
||||||
# 验证主密码(明文比较,按您的要求)
|
# 验证主密码(bcrypt 哈希验证)
|
||||||
if user.UserPassword != password:
|
if not user.CheckPassword(password):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 验证二级密码(明文比较)
|
# 验证二级密码(明文比较)
|
||||||
@@ -10342,9 +10348,10 @@ class AdKftjView(APIView):
|
|||||||
UserUID=generate_yonghuid(),
|
UserUID=generate_yonghuid(),
|
||||||
UserName=f'kefu_{phone}',
|
UserName=f'kefu_{phone}',
|
||||||
Phone=phone,
|
Phone=phone,
|
||||||
UserPassword=password,
|
|
||||||
OpenID=f'kefu_{phone}' # 临时openid
|
OpenID=f'kefu_{phone}' # 临时openid
|
||||||
)
|
)
|
||||||
|
user.SetPassword(password)
|
||||||
|
user.save(update_fields=['UserPassword'])
|
||||||
# 创建客服扩展表
|
# 创建客服扩展表
|
||||||
kefu = UserKefu.query.create(
|
kefu = UserKefu.query.create(
|
||||||
user=user,
|
user=user,
|
||||||
|
|||||||
Reference in New Issue
Block a user