From 335efdb565999c33d98af23e72f2cff28b989fe4 Mon Sep 17 00:00:00 2001 From: Monet Lee Date: Mon, 23 Sep 2024 14:07:08 +0800 Subject: [PATCH] fix: reset UserPassword in admin. (#572) * update dockerfile contents. * update field. * fix: reset UserPassword in admin. --- internal/api/admin/admin.go | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/internal/api/admin/admin.go b/internal/api/admin/admin.go index e0586939..96f15974 100644 --- a/internal/api/admin/admin.go +++ b/internal/api/admin/admin.go @@ -18,6 +18,11 @@ import ( "context" "crypto/md5" "encoding/hex" + "net/http" + "strconv" + "strings" + "time" + "github.com/gin-gonic/gin" "github.com/openimsdk/chat/internal/api/util" "github.com/openimsdk/chat/pkg/common/apistruct" @@ -37,10 +42,6 @@ import ( "github.com/openimsdk/tools/log" "github.com/openimsdk/tools/utils/datautil" "github.com/openimsdk/tools/utils/encrypt" - "net/http" - "strconv" - "strings" - "time" ) func New(chatClient chat.ChatClient, adminClient admin.AdminClient, imApiCaller imapi.CallerInterface, api *util.Api) *Api { @@ -87,7 +88,30 @@ func (o *Api) AdminLogin(c *gin.Context) { } func (o *Api) ResetUserPassword(c *gin.Context) { - a2r.Call(chat.ChatClient.ChangePassword, o.chatClient, c) + req, err := a2r.ParseRequest[chat.ChangePasswordReq](c) + if err != nil { + apiresp.GinError(c, err) + return + } + resp, err := o.chatClient.ChangePassword(c, req) + if err != nil { + apiresp.GinError(c, err) + return + } + + imToken, err := o.imApiCaller.ImAdminTokenWithDefaultAdmin(c) + if err != nil { + apiresp.GinError(c, err) + return + } + + err = o.imApiCaller.ForceOffLine(mctx.WithApiToken(c, imToken), req.UserID) + if err != nil { + apiresp.GinError(c, err) + return + } + + apiresp.GinSuccess(c, resp) } func (o *Api) AdminUpdateInfo(c *gin.Context) {