by Robin at 20240110; login add inviter field
This commit is contained in:
parent
adeb7cea44
commit
1f6a083f93
|
@ -38,6 +38,8 @@ var ErrCodeMsgMap = map[ErrCode]string{
|
|||
|
||||
ErrCodeAccountSrvFail: "账户服务错误",
|
||||
ErrCodeAccountNotExist: "账户信息不存在",
|
||||
ErrCodeAccountInviterNotExist: "邀请人不存在",
|
||||
ErrCodeAccountInviterIsNotAStreamer: "邀请人非主播",
|
||||
|
||||
ErrCodeVasSrvFail: "增值服务错误",
|
||||
ErrCodeVasProductNotExist: "商品不存在",
|
||||
|
@ -191,6 +193,8 @@ const (
|
|||
ErrCodeAccountSrvOk ErrCode = ErrCodeOk
|
||||
ErrCodeAccountSrvFail ErrCode = -6001 //账户服务错误
|
||||
ErrCodeAccountNotExist ErrCode = -6002 //账户信息不存在
|
||||
ErrCodeAccountInviterNotExist ErrCode = -6003 //邀请人不存在,
|
||||
ErrCodeAccountInviterIsNotAStreamer ErrCode = -6004 //邀请人非主播,
|
||||
|
||||
// Vas: 7xxx
|
||||
ErrCodeVasSrvOk ErrCode = ErrCodeOk
|
||||
|
|
|
@ -75,6 +75,7 @@ type ApiLoginByVeriCodeReq struct {
|
|||
base.BaseRequest
|
||||
MobilePhoneInfoComponent `jcrypto:"true"`
|
||||
VeriCodeComponent
|
||||
Inviter *int64 `json:"inviter"`
|
||||
}
|
||||
|
||||
type ApiLoginData struct {
|
||||
|
|
|
@ -75,6 +75,7 @@ type OpLoginByVeriCodeReq struct {
|
|||
base.BaseRequest
|
||||
MobilePhoneInfoComponent `jcrypto:"true"`
|
||||
VeriCodeComponent
|
||||
Inviter *int64 `json:"inviter"`
|
||||
}
|
||||
|
||||
type OpLoginData struct {
|
||||
|
|
|
@ -123,7 +123,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB
|
|||
|
||||
// 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息
|
||||
if ec == errcode.ErrCodeLoginNotExist {
|
||||
login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent)
|
||||
login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter)
|
||||
if ec != errcode.ErrCodeLoginSrvOk {
|
||||
logger.Error("utilRegisterUser failed")
|
||||
ec = errcode.ErrCodeLoginRegisterUserFail
|
||||
|
|
|
@ -106,13 +106,26 @@ func (s *Service) ApiLoginByVeriCodeBusinessValidate(ctx *gin.Context, req *logi
|
|||
// 2.如果错误码是登录信息不存在,则判断为首次登录,业务逻辑将创建用户信息
|
||||
if ec == errcode.ErrCodeLoginNotExist {
|
||||
vericode, _ = resultList[3].(*dbstruct.VeriCode)
|
||||
if req.Inviter != nil {
|
||||
inviter, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{
|
||||
UserId: req.Inviter,
|
||||
})
|
||||
if err != nil || inviter == nil {
|
||||
ec = errcode.ErrCodeAccountInviterNotExist
|
||||
return
|
||||
}
|
||||
if util.DerefInt64(inviter.Role) != consts.Streamer {
|
||||
ec = errcode.ErrCodeAccountInviterIsNotAStreamer
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
} else if ec == errcode.ErrCodeLoginSrvOk {
|
||||
login, _ = resultList[1].(*dbstruct.Login)
|
||||
account, _ = resultList[2].(*dbstruct.Account)
|
||||
vericode, _ = resultList[3].(*dbstruct.VeriCode)
|
||||
} else {
|
||||
logger.Error("ApiLoginByPswd business validation failed!")
|
||||
logger.Error("ApiLoginByVeriCode business validation failed!")
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"service/api/consts"
|
||||
"service/api/errcode"
|
||||
accountproto "service/api/proto/account/proto"
|
||||
accountrelationproto "service/api/proto/accountrelation/proto"
|
||||
|
@ -18,6 +19,7 @@ import (
|
|||
userwxaddcheckproto "service/api/proto/userwxaddcheck/proto"
|
||||
vericodeproto "service/api/proto/vericode/proto"
|
||||
businessvalidator "service/app/mix/service/business_validator"
|
||||
"service/bizcommon/util"
|
||||
"service/dbstruct"
|
||||
"service/library/logger"
|
||||
"service/library/mycrypto"
|
||||
|
@ -112,6 +114,19 @@ func (s *Service) OpLoginByVeriCodeBusinessValidate(ctx *gin.Context, req *login
|
|||
|
||||
// 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息
|
||||
if ec == errcode.ErrCodeLoginNotExist {
|
||||
if req.Inviter != nil {
|
||||
inviter, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{
|
||||
UserId: req.Inviter,
|
||||
})
|
||||
if err != nil || inviter == nil {
|
||||
ec = errcode.ErrCodeAccountInviterNotExist
|
||||
return
|
||||
}
|
||||
if util.DerefInt64(inviter.Role) != consts.Streamer {
|
||||
ec = errcode.ErrCodeAccountInviterIsNotAStreamer
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
} else if ec == errcode.ErrCodeLoginSrvOk {
|
||||
login, _ = resultList[1].(*dbstruct.Login)
|
||||
|
|
|
@ -524,7 +524,7 @@ func (s *Service) OpLoginByVeriCode(ctx *gin.Context, req *loginproto.OpLoginByV
|
|||
|
||||
// 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息
|
||||
if ec == errcode.ErrCodeLoginNotExist {
|
||||
login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent)
|
||||
login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter)
|
||||
if ec != errcode.ErrCodeLoginSrvOk {
|
||||
logger.Error("utilRegisterUser failed")
|
||||
ec = errcode.ErrCodeLoginRegisterUserFail
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
// 不向外暴露的辅助公共函数
|
||||
|
||||
// 注册账户
|
||||
func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhoneInfoComponent) (login *dbstruct.Login, account *dbstruct.Account, ec errcode.ErrCode) {
|
||||
func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhoneInfoComponent, inviter *int64) (login *dbstruct.Login, account *dbstruct.Account, ec errcode.ErrCode) {
|
||||
var err error
|
||||
|
||||
ec = errcode.ErrCodeLoginSrvOk
|
||||
|
@ -44,6 +44,7 @@ func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhone
|
|||
account.MobilePhone = goproto.String(req.MobilePhone)
|
||||
account.RegionCode = goproto.String(req.RegionCode)
|
||||
account.PhoneHash = goproto.String(req.PhoneHash)
|
||||
account.Inviter = inviter
|
||||
|
||||
// 创建账户,生成mid
|
||||
err = _DefaultAccount.OpCreate(ctx, &accountproto.OpCreateReq{
|
||||
|
|
|
@ -20,6 +20,7 @@ type Account struct {
|
|||
IsDndModeEnabled *int64 `json:"is_dnd_mode_enabled" bson:"is_dnd_mode_enabled"` // 是否开启勿扰模式
|
||||
GoldNum *int64 `json:"gold_num" bson:"gold_num"` // 金币数量
|
||||
DiamondNum *int64 `json:"diamond_num" bson:"diamond_num"` // 钻石数量
|
||||
Inviter *int64 `json:"inviter" bson:"inviter"` // 邀请人user_id
|
||||
Latitude *float64 `bson:"latitude"` // 纬度
|
||||
Longitude *float64 `bson:"longitude"` // 经度
|
||||
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||
|
|
|
@ -39,6 +39,9 @@ func (aesCrypto *AesCrypto) Encrypt(msg []byte) (encryptedBytes []byte, err erro
|
|||
}
|
||||
|
||||
func (aesCrypto *AesCrypto) Decrypt(encryptedBytes []byte) (decryptedBytes []byte, err error) {
|
||||
if len(encryptedBytes) == 0 {
|
||||
return
|
||||
}
|
||||
//CBC解密
|
||||
block, _ := aes.NewCipher(aesCrypto.aesPriKey) // 分组秘钥
|
||||
blockSize := block.BlockSize() // 获取秘钥块的长度
|
||||
|
|
|
@ -39,6 +39,9 @@ func (rsaCrypto *RsaCrypto) Encrypt(msg []byte) (encryptedBytes []byte, err erro
|
|||
}
|
||||
|
||||
func (rsaCrypto *RsaCrypto) Decrypt(encryptedBytes []byte) (decryptedBytes []byte, err error) {
|
||||
if len(encryptedBytes) == 0 {
|
||||
return
|
||||
}
|
||||
//私钥解密
|
||||
decryptedBytes, err = rsa.DecryptPKCS1v15(rand.Reader, rsaCrypto.rsaPriKey, encryptedBytes)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue