Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/users/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,13 @@ class RePasswordView(APIView):
def post(self, request: Request):
request_data = request.data
if request_data.get("encrypted", False):
request_data["password"] = decrypt(request_data.get("password"))
request_data["re_password"] = decrypt(request_data.get("re_password"))
# 前端对 password/re_password 先做 JSON.stringify 再 RSA 加密,解密后需反序列化
# 还原真实明文;否则会把带引号的 JSON 字符串当成密码存库,导致登录校验失败。
try:
request_data["password"] = json.loads(decrypt(request_data.get("password")))
request_data["re_password"] = json.loads(decrypt(request_data.get("re_password")))
except Exception:
raise AppApiException(500, _("Invalid encrypted data"))
serializer_obj = RePasswordSerializer(data=request_data)
return result.success(serializer_obj.reset_password())

Expand Down
8 changes: 6 additions & 2 deletions ui/src/views/login/forgot-password/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ const handleResetPassword = async () => {
const encryptor = new JSEncrypt()
encryptor.setPublicKey(auth.baseProfile?.rsa ?? '')
const { confirmPassword: re_password, email, password, verificationCode: code } = forgotPasswordForm
const encryptedData = encryptor.encrypt(JSON.stringify({ password, re_password }))
const encryptedData = encryptor.encrypt(JSON.stringify(password))
if (!encryptedData) {
return
}
const encryptedRePassword = encryptor.encrypt(JSON.stringify(re_password))
if (!encryptedRePassword) {
return
}

await ForgotPasswordApi.postResetPassword({ code, email, password: encryptedData, re_password: encryptedData, encrypted: true })
await ForgotPasswordApi.postResetPassword({ code, email, password: encryptedData, re_password: encryptedRePassword, encrypted: true })
MsgSuccess('密码修改成功,请使用新密码登录')
router.push({ name: 'login' })
} finally {
Expand Down
Loading