From 8f1e63c95aeb8b4978529073237d0d243286ea02 Mon Sep 17 00:00:00 2001 From: zzw <1464003642@qq.com> Date: Wed, 21 Oct 2026 13:55:38 +0800 Subject: [PATCH] feat: user update mobile --- rpc/user/pb/user.pb.go | 15 ++++++++++++--- rpc/user/user.pb | Bin 19262 -> 19289 bytes rpc/user/user.proto | 1 + services/user/internal/logic/updateLogic.go | 8 ++++++++ services/user/validator/user.go | 15 +++++++++------ 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/rpc/user/pb/user.pb.go b/rpc/user/pb/user.pb.go index e5f7164..b79e0cb 100644 --- a/rpc/user/pb/user.pb.go +++ b/rpc/user/pb/user.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.36.11 +// protoc-gen-go v1.36.12 // protoc v3.19.4 // source: user/user.proto @@ -1858,6 +1858,7 @@ type UpdateReq struct { Birthday string `protobuf:"bytes,4,opt,name=birthday,proto3" json:"birthday,omitempty"` Mobile string `protobuf:"bytes,5,opt,name=mobile,proto3" json:"mobile,omitempty"` RealName string `protobuf:"bytes,6,opt,name=real_name,json=realName,proto3" json:"real_name,omitempty"` + SmsCode string `protobuf:"bytes,7,opt,name=sms_code,json=smsCode,proto3" json:"sms_code,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -1934,6 +1935,13 @@ func (x *UpdateReq) GetRealName() string { return "" } +func (x *UpdateReq) GetSmsCode() string { + if x != nil { + return x.SmsCode + } + return "" +} + type PasswordReq struct { state protoimpl.MessageState `protogen:"open.v1"` OldPassword string `protobuf:"bytes,1,opt,name=old_password,json=oldPassword,proto3" json:"old_password,omitempty"` @@ -2332,14 +2340,15 @@ const file_user_user_proto_rawDesc = "" + "\x04code\x18\x01 \x01(\tR\x04code\"#\n" + "\rBindMobileReq\x12\x12\n" + "\x04code\x18\x01 \x01(\tR\x04code\"\t\n" + - "\aInfoReq\"\xa0\x01\n" + + "\aInfoReq\"\xbb\x01\n" + "\tUpdateReq\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x16\n" + "\x06avatar\x18\x02 \x01(\tR\x06avatar\x12\x16\n" + "\x06gender\x18\x03 \x01(\rR\x06gender\x12\x1a\n" + "\bbirthday\x18\x04 \x01(\tR\bbirthday\x12\x16\n" + "\x06mobile\x18\x05 \x01(\tR\x06mobile\x12\x1b\n" + - "\treal_name\x18\x06 \x01(\tR\brealName\"L\n" + + "\treal_name\x18\x06 \x01(\tR\brealName\x12\x19\n" + + "\bsms_code\x18\a \x01(\tR\asmsCode\"L\n" + "\vPasswordReq\x12!\n" + "\fold_password\x18\x01 \x01(\tR\voldPassword\x12\x1a\n" + "\bpassword\x18\x02 \x01(\tR\bpassword\"V\n" + diff --git a/rpc/user/user.pb b/rpc/user/user.pb index b596e4a600267102261e2a1d2020dd9a69c683f7..f288b69aede79b53fbb5aad43c98ea2f3dc23959 100644 GIT binary patch delta 55 zcmdltjq&C*#tlxUOjC6>yO^HlVcb1gz-ghBkR%sJac*&Za(+sx1iJ#G24@gEknfzI KvU!739|r&s#S#Yq delta 28 kcmcaPjd9;J#tlxUOuw`@yO^HlVO%g-z-i&;Gfur60IbdnlmGw# diff --git a/rpc/user/user.proto b/rpc/user/user.proto index 66483da..ac724d7 100644 --- a/rpc/user/user.proto +++ b/rpc/user/user.proto @@ -282,6 +282,7 @@ message UpdateReq { string birthday = 4; string mobile = 5; string real_name = 6; + string sms_code = 7; } message PasswordReq { diff --git a/services/user/internal/logic/updateLogic.go b/services/user/internal/logic/updateLogic.go index 88939cc..8ce8a6d 100644 --- a/services/user/internal/logic/updateLogic.go +++ b/services/user/internal/logic/updateLogic.go @@ -75,6 +75,14 @@ func (l *UpdateLogic) Update(in *user.UpdateReq) (*user.Response, error) { return failResponse(utils.ErrorEncryptAesError), nil } if enc != row.Mobile { + ok, verifyErr := verifyAndConsumeSmsCode(l.ctx, dao.SmsSceneRebindMobile, req.Mobile, req.SmsCode) + if verifyErr != nil { + l.Errorf("update verify sms: %v", verifyErr) + return failResponse(utils.Fail), nil + } + if !ok { + return outResponse(utils.ErrorParams, "验证码错误或已过期"), nil + } occupied, occErr := findUserByMobile(enc) if occErr != nil { l.Errorf("update mobile unique: %v", occErr) diff --git a/services/user/validator/user.go b/services/user/validator/user.go index c4c0421..800fd5e 100644 --- a/services/user/validator/user.go +++ b/services/user/validator/user.go @@ -67,16 +67,19 @@ type UpdateValidator struct { Birthday string `validate:"omitempty,max=32"` Mobile string `validate:"omitempty,len=11"` RealName string `validate:"omitempty,max=64"` + SmsCode string `validate:"required_with=Mobile,omitempty,max=8"` } func (p UpdateValidator) GetMessage() validate.ValidatorMessages { return validate.ValidatorMessages{ - "Name.max": "昵称过长", - "Avatar.max": "头像地址过长", - "Gender.oneof": "性别不正确", - "Birthday.max": "生日过长", - "Mobile.len": "手机号格式不正确", - "RealName.max": "真实姓名过长", + "Name.max": "昵称过长", + "Avatar.max": "头像地址过长", + "Gender.oneof": "性别不正确", + "Birthday.max": "生日过长", + "Mobile.len": "手机号格式不正确", + "RealName.max": "真实姓名过长", + "SmsCode.required_with": "修改手机号时验证码不能为空", + "SmsCode.max": "验证码过长", } }