fix(auth): 修改密码当新密码与旧密码相同时弹出错误,不再退出登录
This commit is contained in:
1 parent
9570197378
commit
0f8b318458
18 files changed
+247
-18
No files matched your search
@@ -235,6 +235,22 @@ def create_user(data: dict[str, Any]) -> dict:
|
||||
|
||||
|
||||
def update_user(user_id: int, data: dict[str, Any]) -> dict:
|
||||
"""
|
||||
更新管理端用户资料,可选同步 Casdoor 改密。
|
||||
|
||||
核心逻辑:先写入本地字段;新密码与当前哈希相同则直接拒绝,避免 Casdoor 返回含 old password 的文案被误判成 401。
|
||||
|
||||
Args:
|
||||
user_id: 目标用户主键。
|
||||
data: 管理端提交的字段,password 为空表示不改密。
|
||||
|
||||
Returns:
|
||||
{'status': 'ok'}。
|
||||
|
||||
Raises:
|
||||
NotFoundError: 用户不存在。
|
||||
AppError: 邮箱非法、新密码未变化或 Casdoor 同步失败。
|
||||
"""
|
||||
user = db.session.get(User, user_id)
|
||||
if not user:
|
||||
raise NotFoundError('User not found')
|
||||
@@ -259,6 +275,12 @@ def update_user(user_id: int, data: dict[str, Any]) -> dict:
|
||||
if 'feature_permissions' in data or 'role' in data:
|
||||
permissions_payload = data.get('feature_permissions', user.feature_permissions)
|
||||
user.set_feature_permissions(permissions_payload)
|
||||
if new_password and user.check_password(new_password):
|
||||
raise AppError(
|
||||
code='AUTH.PASSWORD_UNCHANGED',
|
||||
message='New password must differ from the current password',
|
||||
http_status=400,
|
||||
)
|
||||
if new_password:
|
||||
user.set_password(new_password)
|
||||
if 'agent_ids' in data:
|
||||
|
||||
Reference in new issue
Block a user