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