feat: rebind mobile
CI / changes (push) Successful in 1m57s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 26s
CI / chore (push) Successful in 26s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 1s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 1s
CI / product (push) Successful in 0s
CI / record (push) Successful in 1s
CI / sale (push) Successful in 0s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 28s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / changes (push) Successful in 1m57s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 26s
CI / chore (push) Successful in 26s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 1s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 1s
CI / product (push) Successful in 0s
CI / record (push) Successful in 1s
CI / sale (push) Successful in 0s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 28s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
user "lone-services/rpc/user/pb"
|
||||
"lone-services/services/user/internal/dao"
|
||||
"lone-services/services/user/internal/svc"
|
||||
"lone-services/services/user/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type RebindMobileLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewRebindMobileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RebindMobileLogic {
|
||||
return &RebindMobileLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RebindMobileLogic) RebindMobile(in *user.RebindMobileReq) (*user.Response, error) {
|
||||
var req validator.RebindMobileValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
if req.OldMobile == req.NewMobile {
|
||||
return outResponse(utils.ErrorParams, "新手机号不能与原手机号相同"), nil
|
||||
}
|
||||
|
||||
loginUser := utils.GetUserFromCtx(l.ctx)
|
||||
if loginUser.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
row, err := loadEnabledUser(loginUser.ID)
|
||||
if err != nil {
|
||||
l.Errorf("rebind mobile load user: %v", err)
|
||||
return failResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
if row.Mobile == utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, "用户未绑定手机号"), nil
|
||||
}
|
||||
|
||||
oldEnc, encErr := utils.EncryptPhone(req.OldMobile)
|
||||
if encErr != nil {
|
||||
l.Errorf("rebind mobile encrypt old: %v", encErr)
|
||||
return failResponse(utils.ErrorEncryptAesError), nil
|
||||
}
|
||||
if oldEnc != row.Mobile {
|
||||
return outResponse(utils.ErrorParams, "原手机号不正确"), nil
|
||||
}
|
||||
|
||||
ok, verifyErr := verifyAndConsumeSmsCode(l.ctx, dao.SmsSceneRebindMobile, req.NewMobile, req.SmsCode)
|
||||
if verifyErr != nil {
|
||||
l.Errorf("rebind mobile verify sms: %v", verifyErr)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if !ok {
|
||||
return outResponse(utils.ErrorParams, "验证码错误或已过期"), nil
|
||||
}
|
||||
|
||||
_, updateErr := NewInternalUpdateMobileLogic(l.ctx, l.svcCtx).InternalUpdateMobile(&user.InternalUpdateMobileReq{
|
||||
UserId: loginUser.ID,
|
||||
Mobile: req.NewMobile,
|
||||
})
|
||||
if updateErr != nil {
|
||||
l.Errorf("rebind mobile update: %v", updateErr)
|
||||
if st, ok := status.FromError(updateErr); ok {
|
||||
switch st.Code() {
|
||||
case codes.InvalidArgument:
|
||||
return outResponse(utils.ErrorParams, st.Message()), nil
|
||||
case codes.AlreadyExists:
|
||||
return failResponse(utils.ErrorDataIsExist), nil
|
||||
case codes.NotFound:
|
||||
return failResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
}
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(nil), nil
|
||||
}
|
||||
@@ -75,14 +75,6 @@ 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)
|
||||
|
||||
@@ -68,6 +68,11 @@ func (s *UserServer) BindMobile(ctx context.Context, in *user.BindMobileReq) (*u
|
||||
return l.BindMobile(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) RebindMobile(ctx context.Context, in *user.RebindMobileReq) (*user.Response, error) {
|
||||
l := logic.NewRebindMobileLogic(ctx, s.svcCtx)
|
||||
return l.RebindMobile(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) Client(ctx context.Context, in *user.ClientReq) (*user.Response, error) {
|
||||
l := logic.NewClientLogic(ctx, s.svcCtx)
|
||||
return l.Client(in)
|
||||
|
||||
Reference in New Issue
Block a user