fix: submit verification code
This commit is contained in:
parent
4c8121bfdf
commit
20a05ea195
|
|
@ -134,6 +134,7 @@ type (
|
||||||
|
|
||||||
// SubmitVerificationCodeReq 提交驗證碼以完成驗證
|
// SubmitVerificationCodeReq 提交驗證碼以完成驗證
|
||||||
SubmitVerificationCodeReq {
|
SubmitVerificationCodeReq {
|
||||||
|
Account string `json:"account" validate:"required`
|
||||||
Purpose string `json:"purpose" validate:"required,oneof=email_verification phone_verification"`
|
Purpose string `json:"purpose" validate:"required,oneof=email_verification phone_verification"`
|
||||||
VerifyCode string `json:"verify_code" validate:"required,len=6"`
|
VerifyCode string `json:"verify_code" validate:"required,len=6"`
|
||||||
Authorization
|
Authorization
|
||||||
|
|
|
||||||
|
|
@ -28,31 +28,65 @@ func NewSubmitVerificationCodeLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *SubmitVerificationCodeLogic) SubmitVerificationCode(req *types.SubmitVerificationCodeReq) (*types.RespOK, error) {
|
func (l *SubmitVerificationCodeLogic) SubmitVerificationCode(req *types.SubmitVerificationCodeReq) (*types.RespOK, error) {
|
||||||
var ct mbr.GenerateCodeType
|
acc := ""
|
||||||
|
ct := mbr.GenerateCodeTypeEmail
|
||||||
switch req.Purpose {
|
switch req.Purpose {
|
||||||
case "email_verification":
|
case "email_verification":
|
||||||
ct = mbr.GenerateCodeTypeEmail
|
if !isValidEmail(req.Account) {
|
||||||
|
return nil, errs.InputInvalidFormatError("email is invalid")
|
||||||
|
}
|
||||||
|
acc = req.Account
|
||||||
case "phone_verification":
|
case "phone_verification":
|
||||||
|
phone, isPhone := normalizeTaiwanMobile(req.Account)
|
||||||
|
if !isPhone {
|
||||||
|
return nil, errs.InputInvalidFormatError("phone number is invalid")
|
||||||
|
}
|
||||||
|
acc = phone
|
||||||
ct = mbr.GenerateCodeTypePhone
|
ct = mbr.GenerateCodeTypePhone
|
||||||
default:
|
default:
|
||||||
return &types.RespOK{}, errs.InputInvalidRangeError("failed to get correct verification type")
|
return &types.RespOK{}, errs.InputInvalidRangeError("")
|
||||||
}
|
|
||||||
|
|
||||||
info, err := l.svcCtx.AccountUC.GetUserAccountInfo(l.ctx, member.GetUIDByAccountRequest{Account: token.LoginID(l.ctx)})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先驗證,不刪除
|
// 先驗證,不刪除
|
||||||
if err = l.svcCtx.AccountUC.CheckRefreshCode(l.ctx, member.VerifyRefreshCodeRequest{
|
if err := l.svcCtx.AccountUC.CheckRefreshCode(l.ctx, member.VerifyRefreshCodeRequest{
|
||||||
VerifyCode: req.VerifyCode,
|
VerifyCode: req.VerifyCode,
|
||||||
LoginID: info.Data.LoginID,
|
LoginID: acc,
|
||||||
CodeType: ct,
|
CodeType: ct,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
e := errs.AuthForbiddenError("failed to get verify code").Wrap(err)
|
e := errs.AuthForbiddenError("failed to get verify code").Wrap(err)
|
||||||
|
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
uid := token.UID(l.ctx)
|
||||||
|
switch req.Purpose {
|
||||||
|
case "email_verification":
|
||||||
|
err := l.svcCtx.AccountUC.BindVerifyEmail(l.ctx, uid, acc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
case "phone_verification":
|
||||||
|
err := l.svcCtx.AccountUC.BindVerifyPhone(l.ctx, uid, acc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return &types.RespOK{}, errs.InputInvalidRangeError("")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := l.svcCtx.AccountUC.UpdateStatus(l.ctx, member.UpdateStatusRequest{
|
||||||
|
UID: uid,
|
||||||
|
Status: mbr.AccountStatusActive,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 真的刪除
|
||||||
|
_ = l.svcCtx.AccountUC.VerifyRefreshCode(l.ctx, member.VerifyRefreshCodeRequest{
|
||||||
|
VerifyCode: req.VerifyCode,
|
||||||
|
LoginID: acc,
|
||||||
|
CodeType: ct,
|
||||||
|
})
|
||||||
|
|
||||||
return &types.RespOK{}, nil
|
return &types.RespOK{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ type RespOK struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubmitVerificationCodeReq struct {
|
type SubmitVerificationCodeReq struct {
|
||||||
|
Account string `json:"account" validate:"required`
|
||||||
Purpose string `json:"purpose" validate:"required,oneof=email_verification phone_verification"`
|
Purpose string `json:"purpose" validate:"required,oneof=email_verification phone_verification"`
|
||||||
VerifyCode string `json:"verify_code" validate:"required,len=6"`
|
VerifyCode string `json:"verify_code" validate:"required,len=6"`
|
||||||
Authorization
|
Authorization
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue