From 3879ccf6529a1c04859bf3cc0c7dcc516b956ac2 Mon Sep 17 00:00:00 2001 From: zhaocy Date: Wed, 15 Jun 2022 18:39:40 +0800 Subject: [PATCH] add check --- cmd/robot/robot.go | 13 +++++++++---- cmd/robot/user.go | 2 +- modules/user/api_create.go | 7 +++++-- modules/user/api_login.go | 5 ++--- modules/user/api_logout.go | 7 +++++-- pb/proto/user/user_msg.proto | 32 ++++++++++++-------------------- pb/user_msg.pb.go | 31 ++++++++++++++++++++----------- 7 files changed, 54 insertions(+), 43 deletions(-) diff --git a/cmd/robot/robot.go b/cmd/robot/robot.go index d4d903b57..fe6ce05ec 100644 --- a/cmd/robot/robot.go +++ b/cmd/robot/robot.go @@ -3,6 +3,7 @@ package robot import ( "bytes" "encoding/json" + "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" "io/ioutil" @@ -38,7 +39,7 @@ func (r *Robot) Run() { log.Printf("websocket %s \n", r.opts.WsUrl) if r.opts.Create { //创建新用户 - r.AccountRegister() + r.AccountRegister(r.opts.Account) } else { r.AccountLogin() } @@ -90,7 +91,7 @@ func (r *Robot) onUserLoaded() { // r.FriendBlacklist() // r.FriendAddBlack() // r.FriendDelBlack("") - r.FriendSearch("乐谷5") + // r.FriendSearch("乐谷5") //pack // r.QueryUserPack() @@ -106,9 +107,12 @@ func (r *Robot) SendToClient(msg *pb.UserMessage, rsp proto.Message) error { } //注册账号 -func (r *Robot) AccountRegister() { +func (r *Robot) AccountRegister(account string) { + if account == "" { + log.Fatal("account value is empty") + } //http - regReq := &pb.UserRegisterReq{} + regReq := &pb.UserRegisterReq{Account: account} jsonByte, _ := json.Marshal(regReq) req, err := http.NewRequest("POST", r.opts.RegUrl, bytes.NewReader(jsonByte)) if err != nil { @@ -128,6 +132,7 @@ func (r *Robot) AccountRegister() { if regRsp.Code == pb.ErrorCode_Success { //注册成功 + fmt.Printf("account:%s 注册成功", regRsp.Account) //登录 loginReg := &pb.UserLoginReq{ Sec: r.BuildSecStr(), diff --git a/cmd/robot/user.go b/cmd/robot/user.go index 590476b31..78fc46bb5 100644 --- a/cmd/robot/user.go +++ b/cmd/robot/user.go @@ -30,7 +30,7 @@ func (r *Robot) handleLogin(msg *pb.UserMessage) { r.user = rsp.Data r.onUserLoaded() } else { - r.AccountRegister() //请求Http接口,模拟创建新账号 + r.AccountRegister(r.opts.Account) //请求Http接口,模拟创建新账号 } } diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 447ef41af..b82b2f069 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -1,15 +1,18 @@ package user import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/event" "go_dreamfactory/pb" "go_dreamfactory/utils" ) +func (this *Api_Comp) Create_Check(session comm.IUserSession, req *pb.UserCreateReq) (result map[string]interface{}, code pb.ErrorCode) { + return +} + //创角 -func (this *Api_Comp) Create(ctx context.Context, session comm.IUserSession, req *pb.UserCreateReq) (err error) { +func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interface{}, req *pb.UserCreateReq) (err error) { defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), User_SubType_Create, req, nil) var code pb.ErrorCode diff --git a/modules/user/api_login.go b/modules/user/api_login.go index 3edfc4adf..b58a586ae 100644 --- a/modules/user/api_login.go +++ b/modules/user/api_login.go @@ -1,7 +1,6 @@ package user import ( - "context" "encoding/base64" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/event" @@ -36,13 +35,13 @@ func decodeUserData(base64Str string) *pb.DB_UserData { } //参数校验 -func (this *Api_Comp) Login_Check(session comm.IUserSession, req *pb.GetlistReq) (result map[string]interface{}, code pb.ErrorCode) { +func (this *Api_Comp) Login_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code pb.ErrorCode) { result = map[string]interface{}{} return } //登录 -func (this *Api_Comp) Login(ctx context.Context, session comm.IUserSession, req *pb.UserLoginReq) (err error) { +func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interface{}, req *pb.UserLoginReq) (err error) { var ( code pb.ErrorCode db_user *pb.DB_UserData diff --git a/modules/user/api_logout.go b/modules/user/api_logout.go index 02e640a34..058f8eb18 100644 --- a/modules/user/api_logout.go +++ b/modules/user/api_logout.go @@ -1,14 +1,17 @@ package user import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" ) +func (this *Api_Comp) Logout_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code pb.ErrorCode) { + return +} + //注销 -func (this *Api_Comp) Logout(ctx context.Context, session comm.IUserSession, rsp *pb.UserLoginReq) error { +func (this *Api_Comp) Logout(session comm.IUserSession, result map[string]interface{}, rsp *pb.UserLoginReq) error { log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp) return nil diff --git a/pb/proto/user/user_msg.proto b/pb/proto/user/user_msg.proto index 9fba6e8ac..15af03494 100644 --- a/pb/proto/user/user_msg.proto +++ b/pb/proto/user/user_msg.proto @@ -5,31 +5,23 @@ import "user/user_db.proto"; //用户登录 message UserLoginReq { - string sec= 1;//密文 + string sec = 1; //密文 } -message UserLoginResp { - Cache_UserData data = 1; +message UserLoginResp { Cache_UserData data = 1; } + +message UserRegisterReq { string account = 1; } + +message UserRegisterRsp { + ErrorCode Code = 1; + string account = 2; } - -message UserRegisterReq{ - string account = 1; -} - -message UserRegisterRsp{ - ErrorCode Code = 1; -} - -message UserLoadRsp { - Cache_UserData data = 1; -} +message UserLoadRsp { Cache_UserData data = 1; } //创角 -message UserCreateReq{ - string NickName = 1;//昵称 +message UserCreateReq { + string NickName = 1; //昵称 } -message UserCreateRsp{ - -} \ No newline at end of file +message UserCreateRsp {} \ No newline at end of file diff --git a/pb/user_msg.pb.go b/pb/user_msg.pb.go index 56779ed3b..3f6680d83 100644 --- a/pb/user_msg.pb.go +++ b/pb/user_msg.pb.go @@ -167,7 +167,8 @@ type UserRegisterRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"` + Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"` + Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account"` } func (x *UserRegisterRsp) Reset() { @@ -209,6 +210,13 @@ func (x *UserRegisterRsp) GetCode() ErrorCode { return ErrorCode_Success } +func (x *UserRegisterRsp) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + type UserLoadRsp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -357,18 +365,19 @@ var file_user_user_msg_proto_rawDesc = []byte{ 0x74, 0x61, 0x22, 0x2b, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, - 0x31, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, + 0x4b, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, - 0x64, 0x65, 0x22, 0x32, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x61, 0x64, 0x52, 0x73, - 0x70, 0x12, 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0f, 0x2e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, - 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x2b, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, - 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, - 0x61, 0x6d, 0x65, 0x22, 0x0f, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x52, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x32, 0x0a, 0x0b, + 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x61, 0x64, 0x52, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x43, 0x61, 0x63, 0x68, + 0x65, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x22, 0x2b, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x0f, 0x0a, + 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x73, 0x70, 0x42, 0x06, + 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (