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
@@ -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": "验证码过长",
}
}