feat: user update mobile

This commit is contained in:
zzw
2026-10-21 13:55:38 +08:00
parent 2aac448925
commit 8f1e63c95a
5 changed files with 30 additions and 9 deletions
+12 -3
View File
@@ -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" +
BIN
View File
Binary file not shown.
+1
View File
@@ -282,6 +282,7 @@ message UpdateReq {
string birthday = 4;
string mobile = 5;
string real_name = 6;
string sms_code = 7;
}
message PasswordReq {
@@ -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)
+9 -6
View File
@@ -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": "验证码过长",
}
}