From f3d9852f98649cc46f951177621e9ce39e2d6d03 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 16:37:04 +0800 Subject: [PATCH 01/14] fix --- server/auth/internal/logic/userresetpasswordlogic.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/auth/internal/logic/userresetpasswordlogic.go b/server/auth/internal/logic/userresetpasswordlogic.go index 2d0d75b6..e1e90c5f 100644 --- a/server/auth/internal/logic/userresetpasswordlogic.go +++ b/server/auth/internal/logic/userresetpasswordlogic.go @@ -56,15 +56,21 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error { user := &gmodel.FsUser{} - err := tx.Model(user).Where("id = ?", rt.UserId).Take(user).Error + err := tx.Where("id = ?", rt.UserId).Take(user).Error if err != nil { logx.Error(err) return err } + if *user.PasswordHash != rt.OldPassword { return fmt.Errorf("password had been reset") } - return tx.Update("PasswordHash", rt.NewPassword).Error + + if *user.PasswordHash == rt.NewPassword { + return fmt.Errorf("the password is the same as the old one. It needs to be changed") + } + + return tx.Where("id = ?", rt.UserId).Update("PasswordHash", rt.NewPassword).Error }) if err != nil { From 1e837a6a4b40bbe337687e8e92f3adabc7eb0ad8 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 16:51:32 +0800 Subject: [PATCH 02/14] fix --- fs_template/reset_confirm.tpl | 10 +++------- server/auth/internal/logic/userresetpasswordlogic.go | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/fs_template/reset_confirm.tpl b/fs_template/reset_confirm.tpl index 8a5d848d..c63a5ae8 100644 --- a/fs_template/reset_confirm.tpl +++ b/fs_template/reset_confirm.tpl @@ -147,15 +147,11 @@ function resetPassword() { }) .then(response => { - if (response.ok && response.data.code == 200) { - console.log('Password reset successful'); - // 在这里执行其他成功处理逻辑 - // 显示成功消息或进行其他操作 - document.getElementById('successMessage').innerText = response.data; + if (response.ok ) { + console.log(response.data); + document.getElementById('successMessage').innerText = response.data.msg; } else { console.error('Password reset failed'); - // 在这里执行其他失败处理逻辑 - // 显示失败消息或进行其他操作 document.getElementById('errorMessage').innerText = 'Password reset failed. Please try again.'; } diff --git a/server/auth/internal/logic/userresetpasswordlogic.go b/server/auth/internal/logic/userresetpasswordlogic.go index e1e90c5f..5d38b4ce 100644 --- a/server/auth/internal/logic/userresetpasswordlogic.go +++ b/server/auth/internal/logic/userresetpasswordlogic.go @@ -66,11 +66,11 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa return fmt.Errorf("password had been reset") } - if *user.PasswordHash == rt.NewPassword { + if *user.PasswordHash == req.NewPassword { return fmt.Errorf("the password is the same as the old one. It needs to be changed") } - return tx.Where("id = ?", rt.UserId).Update("PasswordHash", rt.NewPassword).Error + return tx.Where("id = ?", rt.UserId).Update("PasswordHash", req.NewPassword).Error }) if err != nil { From 59d11b3d4e745dd39ec7ab540c757b230420256e Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 16:55:02 +0800 Subject: [PATCH 03/14] fix --- fs_template/reset_confirm.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs_template/reset_confirm.tpl b/fs_template/reset_confirm.tpl index c63a5ae8..ceb896ce 100644 --- a/fs_template/reset_confirm.tpl +++ b/fs_template/reset_confirm.tpl @@ -148,8 +148,8 @@ function resetPassword() { .then(response => { if (response.ok ) { - console.log(response.data); - document.getElementById('successMessage').innerText = response.data.msg; + console.log(response); + document.getElementById('successMessage').innerText = JSON.stringify(response); } else { console.error('Password reset failed'); document.getElementById('errorMessage').innerText = 'Password reset failed. Please try again.'; From ed68e274e2f93f7cb5c70697e0c6c2e76a3a2982 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 16:59:24 +0800 Subject: [PATCH 04/14] fix --- fs_template/reset_confirm.tpl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs_template/reset_confirm.tpl b/fs_template/reset_confirm.tpl index ceb896ce..a62e5eaa 100644 --- a/fs_template/reset_confirm.tpl +++ b/fs_template/reset_confirm.tpl @@ -145,14 +145,15 @@ function resetPassword() { }, body: JSON.stringify(data) }) - .then(response => { + .then(response => response.json()) + .then(data => { - if (response.ok ) { - console.log(response); - document.getElementById('successMessage').innerText = JSON.stringify(response); + if (data.code == 200 ) { + + document.getElementById('successMessage').innerText = JSON.stringify(data); } else { console.error('Password reset failed'); - document.getElementById('errorMessage').innerText = 'Password reset failed. Please try again.'; + document.getElementById('errorMessage').innerText = JSON.stringify(data); } }) From 358e33c6eb5ac01ff6b8f736142ef61d49ad2283 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 17:03:48 +0800 Subject: [PATCH 05/14] fix --- fs_template/reset_confirm.tpl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fs_template/reset_confirm.tpl b/fs_template/reset_confirm.tpl index a62e5eaa..575be923 100644 --- a/fs_template/reset_confirm.tpl +++ b/fs_template/reset_confirm.tpl @@ -147,15 +147,11 @@ function resetPassword() { }) .then(response => response.json()) .then(data => { - if (data.code == 200 ) { - document.getElementById('successMessage').innerText = JSON.stringify(data); } else { - console.error('Password reset failed'); document.getElementById('errorMessage').innerText = JSON.stringify(data); } - }) .catch(error => { console.error('Error:', error); From 3a6eeb316ba41a8b20f91246fc3d49f757e3120e Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 17:07:42 +0800 Subject: [PATCH 06/14] fix --- server/auth/internal/logic/useremailconfirmationlogic.go | 3 +-- server/auth/internal/logic/userresetpasswordlogic.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/server/auth/internal/logic/useremailconfirmationlogic.go b/server/auth/internal/logic/useremailconfirmationlogic.go index fff910f4..1cc25d3b 100644 --- a/server/auth/internal/logic/useremailconfirmationlogic.go +++ b/server/auth/internal/logic/useremailconfirmationlogic.go @@ -81,8 +81,7 @@ func CommonNotify(WebsocketAddr, wid string, event *wevent.WebsocketEvent) error result := wresp.Json() if result.Get("code").Int() != 200 { - // logx.Error(result.Get("message")) - return fmt.Errorf("%s", result.Get("message").Str) + return fmt.Errorf("%s", result.String()) } return nil diff --git a/server/auth/internal/logic/userresetpasswordlogic.go b/server/auth/internal/logic/userresetpasswordlogic.go index 5d38b4ce..4bd392b6 100644 --- a/server/auth/internal/logic/userresetpasswordlogic.go +++ b/server/auth/internal/logic/userresetpasswordlogic.go @@ -75,14 +75,14 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa if err != nil { logx.Error(err) - return resp.SetStatus(basic.CodeDbSqlErr, err.Error()) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error()) } event := wevent.NewWebsocketEventSuccess(wevent.UserResetToken, rt.TraceId) err = CommonNotify(l.svcCtx.Config.MainAddress, rt.Wid, event) if err != nil { logx.Error(err, rt.TraceId) - return resp.SetStatus(basic.CodeResetPasswordErr, err.Error()) + return resp.SetStatusWithMessage(basic.CodeResetPasswordErr, err.Error()) } // token := &auth.ResetToken{ From ca6a10c373b3ea8c54337d32af2d73d28115a080 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 17:11:59 +0800 Subject: [PATCH 07/14] fix --- server/auth/internal/logic/useremailconfirmationlogic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/auth/internal/logic/useremailconfirmationlogic.go b/server/auth/internal/logic/useremailconfirmationlogic.go index 1cc25d3b..1183f8a2 100644 --- a/server/auth/internal/logic/useremailconfirmationlogic.go +++ b/server/auth/internal/logic/useremailconfirmationlogic.go @@ -80,6 +80,7 @@ func CommonNotify(WebsocketAddr, wid string, event *wevent.WebsocketEvent) error } result := wresp.Json() + logx.Error(result.String()) if result.Get("code").Int() != 200 { return fmt.Errorf("%s", result.String()) } From 4342e09699ede96a002a11d17a4f00a8a8d5d703 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 17:24:46 +0800 Subject: [PATCH 08/14] fix --- server/auth/internal/logic/useremailconfirmationlogic.go | 9 +++++++-- server/auth/internal/logic/userresetpasswordlogic.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/auth/internal/logic/useremailconfirmationlogic.go b/server/auth/internal/logic/useremailconfirmationlogic.go index 1183f8a2..53be665f 100644 --- a/server/auth/internal/logic/useremailconfirmationlogic.go +++ b/server/auth/internal/logic/useremailconfirmationlogic.go @@ -67,7 +67,8 @@ func FinishRegister(svcCtx *svc.ServiceContext, user *gmodel.FsUser, token *auth } func CommonNotify(WebsocketAddr, wid string, event *wevent.WebsocketEvent) error { - tp := requests.Post(fmt.Sprintf("%s/api/websocket/common_notify", WebsocketAddr)) + reqWebsocketAddr := fmt.Sprintf("%s/api/websocket/common_notify", WebsocketAddr) + tp := requests.Post(reqWebsocketAddr) tp.SetBodyJson(requests.M{ "wid": wid, "data": event, @@ -80,7 +81,11 @@ func CommonNotify(WebsocketAddr, wid string, event *wevent.WebsocketEvent) error } result := wresp.Json() - logx.Error(result.String()) + + if !result.Get("code").Exists() { + return fmt.Errorf("send %s is error", reqWebsocketAddr) + } + if result.Get("code").Int() != 200 { return fmt.Errorf("%s", result.String()) } diff --git a/server/auth/internal/logic/userresetpasswordlogic.go b/server/auth/internal/logic/userresetpasswordlogic.go index 4bd392b6..7f0c943c 100644 --- a/server/auth/internal/logic/userresetpasswordlogic.go +++ b/server/auth/internal/logic/userresetpasswordlogic.go @@ -79,7 +79,7 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa } event := wevent.NewWebsocketEventSuccess(wevent.UserResetToken, rt.TraceId) - err = CommonNotify(l.svcCtx.Config.MainAddress, rt.Wid, event) + err = CommonNotify(l.svcCtx.Config.WebsocketAddr, rt.Wid, event) if err != nil { logx.Error(err, rt.TraceId) return resp.SetStatusWithMessage(basic.CodeResetPasswordErr, err.Error()) From 1d9b70aa18521b103906f1d9c47638ea46e83e9b Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 17:35:33 +0800 Subject: [PATCH 09/14] fix --- fs_template/reset_confirm.tpl | 9 ++------- server/auth/internal/logic/useremailconfirmationlogic.go | 1 + 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/fs_template/reset_confirm.tpl b/fs_template/reset_confirm.tpl index 575be923..3af017d2 100644 --- a/fs_template/reset_confirm.tpl +++ b/fs_template/reset_confirm.tpl @@ -117,11 +117,6 @@ button:hover { -
-

-

-
-