From 4b443ca61d0772b4fd154bfe34cf329344c723c3 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Wed, 3 Jul 2024 10:33:12 +0800 Subject: [PATCH 1/4] update gomake version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 89b791bd..723dd02e 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( require ( github.com/livekit/protocol v1.10.1 github.com/mitchellh/mapstructure v1.5.0 - github.com/openimsdk/gomake v0.0.9 + github.com/openimsdk/gomake v0.0.14-alpha.5 github.com/openimsdk/protocol v0.0.63 github.com/openimsdk/tools v0.0.49-alpha.24 github.com/redis/go-redis/v9 v9.5.1 diff --git a/go.sum b/go.sum index 012886d2..6587e0cd 100644 --- a/go.sum +++ b/go.sum @@ -185,8 +185,8 @@ github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADym github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/openimsdk/gomake v0.0.9 h1:ouf25ygN2PMQ68Gfgns/EQRPiLPnp+77SIr68GfE+n4= -github.com/openimsdk/gomake v0.0.9/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= +github.com/openimsdk/gomake v0.0.14-alpha.5 h1:VY9c5x515lTfmdhhPjMvR3BBRrRquAUCFsz7t7vbv7Y= +github.com/openimsdk/gomake v0.0.14-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= github.com/openimsdk/protocol v0.0.63 h1:9DnweZe9nEYDFa4fGTbC9Cqi0gLUdtBhRo1NRP2X3WQ= github.com/openimsdk/protocol v0.0.63/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8= github.com/openimsdk/tools v0.0.49-alpha.24 h1:lJsqnjTPujnr91LRQ6QmcTliMIa4fMOBSTri6rFz2ek= From 3926a0b129328507cb52a2a2fbeca6c00b3b4c6c Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Wed, 3 Jul 2024 10:45:47 +0800 Subject: [PATCH 2/4] update gomake version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ed17db92..8090d968 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,7 +43,7 @@ COPY --from=builder $SERVER_DIR/start-config.yml $SERVER_DIR/ COPY --from=builder $SERVER_DIR/go.mod $SERVER_DIR/ COPY --from=builder $SERVER_DIR/go.sum $SERVER_DIR/ -RUN go get github.com/openimsdk/gomake@v0.0.9 +RUN go get github.com/openimsdk/v0.0.14-alpha.5 # Set the command to run when the container starts ENTRYPOINT ["sh", "-c", "mage start && tail -f /dev/null"] From b6a109e7a8ff0ba410c9487405e529d7a7c117c8 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 2 Aug 2024 17:26:29 +0800 Subject: [PATCH 3/4] update version --- pkg/common/config/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/config/version b/pkg/common/config/version index b7c8e167..4e2cea3b 100644 --- a/pkg/common/config/version +++ b/pkg/common/config/version @@ -1 +1 @@ -v1.7.0 \ No newline at end of file +v1.8.0 \ No newline at end of file From cfa0421c9e01c989796f26ac1a648a134ba9e083 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Sun, 29 Sep 2024 11:17:05 +0800 Subject: [PATCH 4/4] fix: mobile phone number, email address, account modification verification --- internal/rpc/chat/login.go | 5 +- internal/rpc/chat/update.go | 6 +- internal/rpc/chat/user.go | 124 +++++++++++++++++++++++++++--------- 3 files changed, 98 insertions(+), 37 deletions(-) diff --git a/internal/rpc/chat/login.go b/internal/rpc/chat/login.go index f1f2474b..59990302 100644 --- a/internal/rpc/chat/login.go +++ b/internal/rpc/chat/login.go @@ -240,8 +240,6 @@ func (o *chatSvr) genVerifyCode() string { } func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) (*chat.RegisterUserResp, error) { - resp := &chat.RegisterUserResp{} - isAdmin, err := o.Admin.CheckNilOrAdmin(ctx) ctx = o.WithAdminUser(ctx) if err != nil { @@ -389,6 +387,7 @@ func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) ( log.ZError(ctx, "UseInvitationCode", err, "userID", req.User.UserID, "invitationCode", req.InvitationCode) } } + var resp chat.RegisterUserResp if req.AutoLogin { chatToken, err := o.Admin.CreateToken(ctx, req.User.UserID, constant.NormalUser) if err == nil { @@ -398,7 +397,7 @@ func (o *chatSvr) RegisterUser(ctx context.Context, req *chat.RegisterUserReq) ( } } resp.UserID = req.User.UserID - return resp, nil + return &resp, nil } func (o *chatSvr) Login(ctx context.Context, req *chat.LoginReq) (*chat.LoginResp, error) { diff --git a/internal/rpc/chat/update.go b/internal/rpc/chat/update.go index 169694ff..4579f1c3 100644 --- a/internal/rpc/chat/update.go +++ b/internal/rpc/chat/update.go @@ -63,8 +63,8 @@ func ToDBAttributeUpdate(req *chat.UpdateUserInfoReq) (map[string]any, error) { if req.GlobalRecvMsgOpt != nil { update["global_recv_msg_opt"] = req.GlobalRecvMsgOpt.Value } - if len(update) == 0 { - return nil, errs.ErrArgs.WrapMsg("no update info") - } + //if len(update) == 0 { + // return nil, errs.ErrArgs.WrapMsg("no update info") + //} return update, nil } diff --git a/internal/rpc/chat/user.go b/internal/rpc/chat/user.go index ff53c917..ce789613 100644 --- a/internal/rpc/chat/user.go +++ b/internal/rpc/chat/user.go @@ -32,8 +32,95 @@ import ( "github.com/openimsdk/tools/errs" ) +func (o *chatSvr) checkUpdateInfo(ctx context.Context, req *chat.UpdateUserInfoReq) error { + attribute, err := o.Database.TakeAttributeByUserID(ctx, req.UserID) + if err != nil { + return err + } + checkEmail := func() error { + if req.Email == nil { + return nil + } + if req.Email.Value == attribute.Email { + req.Email = nil + return nil + } + if req.Email.Value == "" { + if !(attribute.Account != "" || (attribute.AreaCode != "" && attribute.PhoneNumber != "")) { + return errs.ErrArgs.WrapMsg("a login method must exist") + } + return nil + } else { + if _, err := o.Database.GetAttributeByEmail(ctx, req.Email.Value); err == nil { + return errs.ErrDuplicateKey.WrapMsg("email already exists") + } else if !dbutil.IsDBNotFound(err) { + return err + } + } + return nil + } + checkPhone := func() error { + if req.AreaCode == nil { + return nil + } + if req.AreaCode.Value == attribute.AreaCode && req.PhoneNumber.Value == attribute.PhoneNumber { + req.AreaCode = nil + req.PhoneNumber = nil + return nil + } + if req.AreaCode.Value == "" || req.PhoneNumber.Value == "" { + if attribute.Email == "" || attribute.Account == "" { + return errs.ErrArgs.WrapMsg("a login method must exist") + } + } else { + if _, err := o.Database.GetAttributeByPhone(ctx, req.AreaCode.Value, req.PhoneNumber.Value); err == nil { + return errs.ErrDuplicateKey.WrapMsg("phone number already exists") + } else if !dbutil.IsDBNotFound(err) { + return err + } + } + return nil + } + checkAccount := func() error { + if req.Account == nil { + return nil + } + if req.Account.Value == attribute.Account { + req.Account = nil + return nil + } + if req.Account.Value == "" { + if !(attribute.Email == "" && (attribute.AreaCode == "" || attribute.PhoneNumber == "")) { + return errs.ErrArgs.WrapMsg("a login method must exist") + } + } else { + if _, err := o.Database.GetAttributeByAccount(ctx, req.Account.Value); err == nil { + return errs.ErrDuplicateKey.WrapMsg("account already exists") + } else if !dbutil.IsDBNotFound(err) { + return err + } + } + return nil + } + for _, fn := range []func() error{checkEmail, checkPhone, checkAccount} { + if err := fn(); err != nil { + return err + } + } + return nil +} + func (o *chatSvr) UpdateUserInfo(ctx context.Context, req *chat.UpdateUserInfoReq) (*chat.UpdateUserInfoResp, error) { - resp := &chat.UpdateUserInfoResp{} + if req.AreaCode != nil || req.PhoneNumber != nil { + if !(req.AreaCode != nil && req.PhoneNumber != nil) { + return nil, errs.ErrArgs.WrapMsg("areaCode and phoneNumber must be set together") + } + if req.AreaCode.Value == "" || req.PhoneNumber.Value == "" { + if req.AreaCode.Value != req.PhoneNumber.Value { + return nil, errs.ErrArgs.WrapMsg("areaCode and phoneNumber must be set together") + } + } + } opUserID, userType, err := mctx.Check(ctx) if err != nil { return nil, err @@ -65,44 +152,19 @@ func (o *chatSvr) UpdateUserInfo(ctx context.Context, req *chat.UpdateUserInfoRe default: return nil, errs.ErrNoPermission.WrapMsg("user type error") } - update, err := ToDBAttributeUpdate(req) - if err != nil { + if err := o.checkUpdateInfo(ctx, req); err != nil { return nil, err } - attribute, err := o.Database.TakeAttributeByUserID(ctx, req.UserID) + update, err := ToDBAttributeUpdate(req) if err != nil { return nil, err } - if req.Account != nil && req.Account.Value != attribute.Account { - _, err := o.Database.TakeAttributeByAccount(ctx, req.Account.Value) - if err == nil { - return nil, eerrs.ErrAccountAlreadyRegister.Wrap() - } else if !dbutil.IsDBNotFound(err) { + if len(update) > 0 { + if err := o.Database.UpdateUseInfo(ctx, req.UserID, update); err != nil { return nil, err } } - if req.AreaCode != nil || req.PhoneNumber != nil { - areaCode := attribute.AreaCode - phoneNumber := attribute.PhoneNumber - if req.AreaCode != nil { - areaCode = req.AreaCode.Value - } - if req.PhoneNumber != nil { - phoneNumber = req.PhoneNumber.Value - } - if attribute.AreaCode != areaCode || attribute.PhoneNumber != phoneNumber { - _, err := o.Database.TakeAttributeByPhone(ctx, areaCode, phoneNumber) - if err == nil { - return nil, eerrs.ErrAccountAlreadyRegister.Wrap() - } else if !dbutil.IsDBNotFound(err) { - return nil, err - } - } - } - if err := o.Database.UpdateUseInfo(ctx, req.UserID, update); err != nil { - return nil, err - } - return resp, nil + return &chat.UpdateUserInfoResp{}, nil } func (o *chatSvr) FindUserPublicInfo(ctx context.Context, req *chat.FindUserPublicInfoReq) (*chat.FindUserPublicInfoResp, error) {