|
|
@ -20,38 +20,41 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
|
|
|
func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
|
|
|
log.NewInfo(req.OperationID, "UserRegister args ", req.String())
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
|
|
|
var user db.User
|
|
|
|
var user db.User
|
|
|
|
utils.CopyStructFields(&user, req.UserInfo)
|
|
|
|
utils.CopyStructFields(&user, req.UserInfo)
|
|
|
|
if req.UserInfo.Birth != 0 {
|
|
|
|
if req.UserInfo.Birth != 0 {
|
|
|
|
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
|
|
|
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(req.OperationID, "copy ", user, req.UserInfo)
|
|
|
|
err := imdb.UserRegister(user)
|
|
|
|
err := imdb.UserRegister(user)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "UserRegister failed ", err.Error(), user)
|
|
|
|
errMsg := req.OperationID + " imdb.UserRegister failed " + err.Error() + user.UserID
|
|
|
|
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
log.NewError(req.OperationID, errMsg, user)
|
|
|
|
|
|
|
|
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "rpc UserRegister return")
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}})
|
|
|
|
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil
|
|
|
|
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
|
|
|
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
|
|
|
log.NewInfo(req.OperationID, "UserToken args ", req.String())
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
|
|
|
|
|
|
|
|
|
|
|
_, err := imdb.GetUserByUserID(req.FromUserID)
|
|
|
|
_, err := imdb.GetUserByUserID(req.FromUserID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID)
|
|
|
|
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.FromUserID
|
|
|
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
|
|
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, req.Platform)
|
|
|
|
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, req.Platform)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "CreateToken failed ", err.Error(), req.FromUserID, req.Platform)
|
|
|
|
errMsg := req.OperationID + " token_verify.CreateToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
|
|
|
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
|
|
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "rpc UserToken return ", tokens, expTime)
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime})
|
|
|
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime}, nil
|
|
|
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -73,15 +76,16 @@ func NewRpcAuthServer(port int) *rpcAuth {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (rpc *rpcAuth) Run() {
|
|
|
|
func (rpc *rpcAuth) Run() {
|
|
|
|
log.NewInfo("0", "rpc auth start...")
|
|
|
|
operationID := utils.OperationIDGenerator()
|
|
|
|
|
|
|
|
log.NewInfo(operationID, "rpc auth start...")
|
|
|
|
|
|
|
|
|
|
|
|
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
|
|
|
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
|
|
|
listener, err := net.Listen("tcp", address)
|
|
|
|
listener, err := net.Listen("tcp", address)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError("0", "listen network failed ", err.Error(), address)
|
|
|
|
log.NewError(operationID, "listen network failed ", err.Error(), address)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.NewInfo("0", "listen network success, ", address, listener)
|
|
|
|
log.NewInfo(operationID, "listen network success, ", address, listener)
|
|
|
|
//grpc server
|
|
|
|
//grpc server
|
|
|
|
srv := grpc.NewServer()
|
|
|
|
srv := grpc.NewServer()
|
|
|
|
defer srv.GracefulStop()
|
|
|
|
defer srv.GracefulStop()
|
|
|
@ -90,15 +94,15 @@ func (rpc *rpcAuth) Run() {
|
|
|
|
pbAuth.RegisterAuthServer(srv, rpc)
|
|
|
|
pbAuth.RegisterAuthServer(srv, rpc)
|
|
|
|
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
|
|
|
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError("0", "RegisterEtcd failed ", err.Error(),
|
|
|
|
log.NewError(operationID, "RegisterEtcd failed ", err.Error(),
|
|
|
|
rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
|
|
|
rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.NewInfo("0", "RegisterAuthServer ok ", rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
|
|
|
log.NewInfo(operationID, "RegisterAuthServer ok ", rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
|
|
|
err = srv.Serve(listener)
|
|
|
|
err = srv.Serve(listener)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError("0", "Serve failed ", err.Error())
|
|
|
|
log.NewError(operationID, "Serve failed ", err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.NewInfo("0", "rpc auth ok")
|
|
|
|
log.NewInfo(operationID, "rpc auth ok")
|
|
|
|
}
|
|
|
|
}
|
|
|
|