From 582174a8bd5ff308e968df1e3e6f6293643d26a1 Mon Sep 17 00:00:00 2001 From: zzw <1464003642@qq.com> Date: Wed, 4 Nov 2026 14:51:39 +0800 Subject: [PATCH] feat: user logout --- rpc/user/pb/user.pb.go | 201 +++++++++++------- rpc/user/pb/user_grpc.pb.go | 38 ++++ rpc/user/user.pb | Bin 20109 -> 20197 bytes rpc/user/user.proto | 8 + .../logic/analysisuser/userStatusLogic.go | 3 - services/user/internal/logic/logoutLogic.go | 87 ++++++++ services/user/internal/server/userServer.go | 5 + services/user/userClient/user.go | 7 + 8 files changed, 266 insertions(+), 83 deletions(-) create mode 100644 services/user/internal/logic/logoutLogic.go diff --git a/rpc/user/pb/user.pb.go b/rpc/user/pb/user.pb.go index d383550..af86ce8 100644 --- a/rpc/user/pb/user.pb.go +++ b/rpc/user/pb/user.pb.go @@ -2179,6 +2179,42 @@ func (*InfoReq) Descriptor() ([]byte, []int) { return file_user_user_proto_rawDescGZIP(), []int{34} } +type LogoutReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LogoutReq) Reset() { + *x = LogoutReq{} + mi := &file_user_user_proto_msgTypes[35] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LogoutReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LogoutReq) ProtoMessage() {} + +func (x *LogoutReq) ProtoReflect() protoreflect.Message { + mi := &file_user_user_proto_msgTypes[35] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LogoutReq.ProtoReflect.Descriptor instead. +func (*LogoutReq) Descriptor() ([]byte, []int) { + return file_user_user_proto_rawDescGZIP(), []int{35} +} + type UpdateReq struct { state protoimpl.MessageState `protogen:"open.v1"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -2193,7 +2229,7 @@ type UpdateReq struct { func (x *UpdateReq) Reset() { *x = UpdateReq{} - mi := &file_user_user_proto_msgTypes[35] + mi := &file_user_user_proto_msgTypes[36] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2205,7 +2241,7 @@ func (x *UpdateReq) String() string { func (*UpdateReq) ProtoMessage() {} func (x *UpdateReq) ProtoReflect() protoreflect.Message { - mi := &file_user_user_proto_msgTypes[35] + mi := &file_user_user_proto_msgTypes[36] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2218,7 +2254,7 @@ func (x *UpdateReq) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateReq.ProtoReflect.Descriptor instead. func (*UpdateReq) Descriptor() ([]byte, []int) { - return file_user_user_proto_rawDescGZIP(), []int{35} + return file_user_user_proto_rawDescGZIP(), []int{36} } func (x *UpdateReq) GetName() string { @@ -2273,7 +2309,7 @@ type PasswordReq struct { func (x *PasswordReq) Reset() { *x = PasswordReq{} - mi := &file_user_user_proto_msgTypes[36] + mi := &file_user_user_proto_msgTypes[37] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2285,7 +2321,7 @@ func (x *PasswordReq) String() string { func (*PasswordReq) ProtoMessage() {} func (x *PasswordReq) ProtoReflect() protoreflect.Message { - mi := &file_user_user_proto_msgTypes[36] + mi := &file_user_user_proto_msgTypes[37] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2298,7 +2334,7 @@ func (x *PasswordReq) ProtoReflect() protoreflect.Message { // Deprecated: Use PasswordReq.ProtoReflect.Descriptor instead. func (*PasswordReq) Descriptor() ([]byte, []int) { - return file_user_user_proto_rawDescGZIP(), []int{36} + return file_user_user_proto_rawDescGZIP(), []int{37} } func (x *PasswordReq) GetPassword() string { @@ -2326,7 +2362,7 @@ type ClientReq struct { func (x *ClientReq) Reset() { *x = ClientReq{} - mi := &file_user_user_proto_msgTypes[37] + mi := &file_user_user_proto_msgTypes[38] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2338,7 +2374,7 @@ func (x *ClientReq) String() string { func (*ClientReq) ProtoMessage() {} func (x *ClientReq) ProtoReflect() protoreflect.Message { - mi := &file_user_user_proto_msgTypes[37] + mi := &file_user_user_proto_msgTypes[38] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2351,7 +2387,7 @@ func (x *ClientReq) ProtoReflect() protoreflect.Message { // Deprecated: Use ClientReq.ProtoReflect.Descriptor instead. func (*ClientReq) Descriptor() ([]byte, []int) { - return file_user_user_proto_rawDescGZIP(), []int{37} + return file_user_user_proto_rawDescGZIP(), []int{38} } func (x *ClientReq) GetName() string { @@ -2384,7 +2420,7 @@ type GenerateQrcodeReq struct { func (x *GenerateQrcodeReq) Reset() { *x = GenerateQrcodeReq{} - mi := &file_user_user_proto_msgTypes[38] + mi := &file_user_user_proto_msgTypes[39] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2396,7 +2432,7 @@ func (x *GenerateQrcodeReq) String() string { func (*GenerateQrcodeReq) ProtoMessage() {} func (x *GenerateQrcodeReq) ProtoReflect() protoreflect.Message { - mi := &file_user_user_proto_msgTypes[38] + mi := &file_user_user_proto_msgTypes[39] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2409,7 +2445,7 @@ func (x *GenerateQrcodeReq) ProtoReflect() protoreflect.Message { // Deprecated: Use GenerateQrcodeReq.ProtoReflect.Descriptor instead. func (*GenerateQrcodeReq) Descriptor() ([]byte, []int) { - return file_user_user_proto_rawDescGZIP(), []int{38} + return file_user_user_proto_rawDescGZIP(), []int{39} } func (x *GenerateQrcodeReq) GetClientCode() string { @@ -2428,7 +2464,7 @@ type QrcodeScanReq struct { func (x *QrcodeScanReq) Reset() { *x = QrcodeScanReq{} - mi := &file_user_user_proto_msgTypes[39] + mi := &file_user_user_proto_msgTypes[40] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2440,7 +2476,7 @@ func (x *QrcodeScanReq) String() string { func (*QrcodeScanReq) ProtoMessage() {} func (x *QrcodeScanReq) ProtoReflect() protoreflect.Message { - mi := &file_user_user_proto_msgTypes[39] + mi := &file_user_user_proto_msgTypes[40] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2453,7 +2489,7 @@ func (x *QrcodeScanReq) ProtoReflect() protoreflect.Message { // Deprecated: Use QrcodeScanReq.ProtoReflect.Descriptor instead. func (*QrcodeScanReq) Descriptor() ([]byte, []int) { - return file_user_user_proto_rawDescGZIP(), []int{39} + return file_user_user_proto_rawDescGZIP(), []int{40} } func (x *QrcodeScanReq) GetSessionId() string { @@ -2473,7 +2509,7 @@ type QrcodeLoginReq struct { func (x *QrcodeLoginReq) Reset() { *x = QrcodeLoginReq{} - mi := &file_user_user_proto_msgTypes[40] + mi := &file_user_user_proto_msgTypes[41] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2485,7 +2521,7 @@ func (x *QrcodeLoginReq) String() string { func (*QrcodeLoginReq) ProtoMessage() {} func (x *QrcodeLoginReq) ProtoReflect() protoreflect.Message { - mi := &file_user_user_proto_msgTypes[40] + mi := &file_user_user_proto_msgTypes[41] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2498,7 +2534,7 @@ func (x *QrcodeLoginReq) ProtoReflect() protoreflect.Message { // Deprecated: Use QrcodeLoginReq.ProtoReflect.Descriptor instead. func (*QrcodeLoginReq) Descriptor() ([]byte, []int) { - return file_user_user_proto_rawDescGZIP(), []int{40} + return file_user_user_proto_rawDescGZIP(), []int{41} } func (x *QrcodeLoginReq) GetSessionId() string { @@ -2685,7 +2721,8 @@ const file_user_user_proto_rawDesc = "" + "\n" + "new_mobile\x18\x02 \x01(\tR\tnewMobile\x12\x19\n" + "\bsms_code\x18\x03 \x01(\tR\asmsCode\"\t\n" + - "\aInfoReq\"\xa0\x01\n" + + "\aInfoReq\"\v\n" + + "\tLogoutReq\"\xa0\x01\n" + "\tUpdateReq\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x16\n" + "\x06avatar\x18\x02 \x01(\tR\x06avatar\x12\x16\n" + @@ -2709,9 +2746,10 @@ const file_user_user_proto_rawDesc = "" + "\x0eQrcodeLoginReq\x12\x1d\n" + "\n" + "session_id\x18\x01 \x01(\tR\tsessionId\x12\x12\n" + - "\x04type\x18\x02 \x01(\x05R\x04type2\xa0\x10\n" + + "\x04type\x18\x02 \x01(\x05R\x04type2\xeb\x10\n" + "\x04User\x12F\n" + - "\x05Login\x12\x0e.user.LoginReq\x1a\x0e.user.Response\"\x1d\x82\xd3\xe4\x93\x02\x17:\x01*\"\x12/api/v3/user/login\x12b\n" + + "\x05Login\x12\x0e.user.LoginReq\x1a\x0e.user.Response\"\x1d\x82\xd3\xe4\x93\x02\x17:\x01*\"\x12/api/v3/user/login\x12I\n" + + "\x06Logout\x12\x0f.user.LogoutReq\x1a\x0e.user.Response\"\x1e\x82\xd3\xe4\x93\x02\x18:\x01*\"\x13/api/v3/user/logout\x12b\n" + "\x0eGenerateQrcode\x12\x17.user.GenerateQrcodeReq\x1a\x0e.user.Response\"'\x82\xd3\xe4\x93\x02!:\x01*\"\x1c/api/v3/user/qrcode/generate\x12V\n" + "\n" + "QrcodeScan\x12\x13.user.QrcodeScanReq\x1a\x0e.user.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\"\x18/api/v3/user/qrcode/scan\x12Y\n" + @@ -2752,7 +2790,7 @@ func file_user_user_proto_rawDescGZIP() []byte { return file_user_user_proto_rawDescData } -var file_user_user_proto_msgTypes = make([]protoimpl.MessageInfo, 41) +var file_user_user_proto_msgTypes = make([]protoimpl.MessageInfo, 42) var file_user_user_proto_goTypes = []any{ (*Response)(nil), // 0: user.Response (*LoginReq)(nil), // 1: user.LoginReq @@ -2789,69 +2827,72 @@ var file_user_user_proto_goTypes = []any{ (*BindMobileReq)(nil), // 32: user.BindMobileReq (*RebindMobileReq)(nil), // 33: user.RebindMobileReq (*InfoReq)(nil), // 34: user.InfoReq - (*UpdateReq)(nil), // 35: user.UpdateReq - (*PasswordReq)(nil), // 36: user.PasswordReq - (*ClientReq)(nil), // 37: user.ClientReq - (*GenerateQrcodeReq)(nil), // 38: user.GenerateQrcodeReq - (*QrcodeScanReq)(nil), // 39: user.QrcodeScanReq - (*QrcodeLoginReq)(nil), // 40: user.QrcodeLoginReq + (*LogoutReq)(nil), // 35: user.LogoutReq + (*UpdateReq)(nil), // 36: user.UpdateReq + (*PasswordReq)(nil), // 37: user.PasswordReq + (*ClientReq)(nil), // 38: user.ClientReq + (*GenerateQrcodeReq)(nil), // 39: user.GenerateQrcodeReq + (*QrcodeScanReq)(nil), // 40: user.QrcodeScanReq + (*QrcodeLoginReq)(nil), // 41: user.QrcodeLoginReq } var file_user_user_proto_depIdxs = []int32{ 7, // 0: user.InternalUsersByIdsData.items:type_name -> user.UserBriefItem 14, // 1: user.InternalDeleteUserData.clients:type_name -> user.InternalDeleteUserClient 27, // 2: user.InternalUsersByBizData.items:type_name -> user.BizUserItem 1, // 3: user.User.Login:input_type -> user.LoginReq - 38, // 4: user.User.GenerateQrcode:input_type -> user.GenerateQrcodeReq - 39, // 5: user.User.QrcodeScan:input_type -> user.QrcodeScanReq - 40, // 6: user.User.QrcodeLogin:input_type -> user.QrcodeLoginReq - 34, // 7: user.User.Info:input_type -> user.InfoReq - 35, // 8: user.User.Update:input_type -> user.UpdateReq - 36, // 9: user.User.Password:input_type -> user.PasswordReq - 31, // 10: user.User.GetOpenid:input_type -> user.GetOpenidReq - 32, // 11: user.User.BindMobile:input_type -> user.BindMobileReq - 33, // 12: user.User.RebindMobile:input_type -> user.RebindMobileReq - 37, // 13: user.User.Client:input_type -> user.ClientReq - 2, // 14: user.User.UserItems:input_type -> user.UserItemsReq - 3, // 15: user.User.UserStatus:input_type -> user.UserStatusReq - 4, // 16: user.User.InternalCreate:input_type -> user.InternalCreateReq - 16, // 17: user.User.InternalCheckCreate:input_type -> user.InternalCheckCreateReq - 18, // 18: user.User.InternalCheckUpdate:input_type -> user.InternalCheckUpdateReq - 20, // 19: user.User.InternalUpdate:input_type -> user.InternalUpdateReq - 6, // 20: user.User.InternalUsersByIds:input_type -> user.InternalUsersByIdsReq - 9, // 21: user.User.InternalUpdateMobile:input_type -> user.InternalUpdateMobileReq - 11, // 22: user.User.InternalRevokeBizClient:input_type -> user.InternalRevokeBizClientReq - 13, // 23: user.User.InternalDeleteUser:input_type -> user.InternalDeleteUserReq - 22, // 24: user.User.InternalGetUserInfo:input_type -> user.InternalGetUserInfoReq - 24, // 25: user.User.InternalVerifyPassword:input_type -> user.InternalVerifyPasswordReq - 26, // 26: user.User.InternalUsersByBiz:input_type -> user.InternalUsersByBizReq - 29, // 27: user.User.InternalLoginByUserId:input_type -> user.InternalLoginByUserIdReq - 0, // 28: user.User.Login:output_type -> user.Response - 0, // 29: user.User.GenerateQrcode:output_type -> user.Response - 0, // 30: user.User.QrcodeScan:output_type -> user.Response - 0, // 31: user.User.QrcodeLogin:output_type -> user.Response - 0, // 32: user.User.Info:output_type -> user.Response - 0, // 33: user.User.Update:output_type -> user.Response - 0, // 34: user.User.Password:output_type -> user.Response - 0, // 35: user.User.GetOpenid:output_type -> user.Response - 0, // 36: user.User.BindMobile:output_type -> user.Response - 0, // 37: user.User.RebindMobile:output_type -> user.Response - 0, // 38: user.User.Client:output_type -> user.Response - 0, // 39: user.User.UserItems:output_type -> user.Response - 0, // 40: user.User.UserStatus:output_type -> user.Response - 5, // 41: user.User.InternalCreate:output_type -> user.InternalCreateData - 17, // 42: user.User.InternalCheckCreate:output_type -> user.InternalCheckCreateData - 19, // 43: user.User.InternalCheckUpdate:output_type -> user.InternalCheckUpdateData - 21, // 44: user.User.InternalUpdate:output_type -> user.InternalUpdateData - 8, // 45: user.User.InternalUsersByIds:output_type -> user.InternalUsersByIdsData - 10, // 46: user.User.InternalUpdateMobile:output_type -> user.InternalUpdateMobileData - 12, // 47: user.User.InternalRevokeBizClient:output_type -> user.InternalRevokeBizClientData - 15, // 48: user.User.InternalDeleteUser:output_type -> user.InternalDeleteUserData - 23, // 49: user.User.InternalGetUserInfo:output_type -> user.InternalGetUserInfoData - 25, // 50: user.User.InternalVerifyPassword:output_type -> user.InternalVerifyPasswordData - 28, // 51: user.User.InternalUsersByBiz:output_type -> user.InternalUsersByBizData - 30, // 52: user.User.InternalLoginByUserId:output_type -> user.InternalLoginByUserIdData - 28, // [28:53] is the sub-list for method output_type - 3, // [3:28] is the sub-list for method input_type + 35, // 4: user.User.Logout:input_type -> user.LogoutReq + 39, // 5: user.User.GenerateQrcode:input_type -> user.GenerateQrcodeReq + 40, // 6: user.User.QrcodeScan:input_type -> user.QrcodeScanReq + 41, // 7: user.User.QrcodeLogin:input_type -> user.QrcodeLoginReq + 34, // 8: user.User.Info:input_type -> user.InfoReq + 36, // 9: user.User.Update:input_type -> user.UpdateReq + 37, // 10: user.User.Password:input_type -> user.PasswordReq + 31, // 11: user.User.GetOpenid:input_type -> user.GetOpenidReq + 32, // 12: user.User.BindMobile:input_type -> user.BindMobileReq + 33, // 13: user.User.RebindMobile:input_type -> user.RebindMobileReq + 38, // 14: user.User.Client:input_type -> user.ClientReq + 2, // 15: user.User.UserItems:input_type -> user.UserItemsReq + 3, // 16: user.User.UserStatus:input_type -> user.UserStatusReq + 4, // 17: user.User.InternalCreate:input_type -> user.InternalCreateReq + 16, // 18: user.User.InternalCheckCreate:input_type -> user.InternalCheckCreateReq + 18, // 19: user.User.InternalCheckUpdate:input_type -> user.InternalCheckUpdateReq + 20, // 20: user.User.InternalUpdate:input_type -> user.InternalUpdateReq + 6, // 21: user.User.InternalUsersByIds:input_type -> user.InternalUsersByIdsReq + 9, // 22: user.User.InternalUpdateMobile:input_type -> user.InternalUpdateMobileReq + 11, // 23: user.User.InternalRevokeBizClient:input_type -> user.InternalRevokeBizClientReq + 13, // 24: user.User.InternalDeleteUser:input_type -> user.InternalDeleteUserReq + 22, // 25: user.User.InternalGetUserInfo:input_type -> user.InternalGetUserInfoReq + 24, // 26: user.User.InternalVerifyPassword:input_type -> user.InternalVerifyPasswordReq + 26, // 27: user.User.InternalUsersByBiz:input_type -> user.InternalUsersByBizReq + 29, // 28: user.User.InternalLoginByUserId:input_type -> user.InternalLoginByUserIdReq + 0, // 29: user.User.Login:output_type -> user.Response + 0, // 30: user.User.Logout:output_type -> user.Response + 0, // 31: user.User.GenerateQrcode:output_type -> user.Response + 0, // 32: user.User.QrcodeScan:output_type -> user.Response + 0, // 33: user.User.QrcodeLogin:output_type -> user.Response + 0, // 34: user.User.Info:output_type -> user.Response + 0, // 35: user.User.Update:output_type -> user.Response + 0, // 36: user.User.Password:output_type -> user.Response + 0, // 37: user.User.GetOpenid:output_type -> user.Response + 0, // 38: user.User.BindMobile:output_type -> user.Response + 0, // 39: user.User.RebindMobile:output_type -> user.Response + 0, // 40: user.User.Client:output_type -> user.Response + 0, // 41: user.User.UserItems:output_type -> user.Response + 0, // 42: user.User.UserStatus:output_type -> user.Response + 5, // 43: user.User.InternalCreate:output_type -> user.InternalCreateData + 17, // 44: user.User.InternalCheckCreate:output_type -> user.InternalCheckCreateData + 19, // 45: user.User.InternalCheckUpdate:output_type -> user.InternalCheckUpdateData + 21, // 46: user.User.InternalUpdate:output_type -> user.InternalUpdateData + 8, // 47: user.User.InternalUsersByIds:output_type -> user.InternalUsersByIdsData + 10, // 48: user.User.InternalUpdateMobile:output_type -> user.InternalUpdateMobileData + 12, // 49: user.User.InternalRevokeBizClient:output_type -> user.InternalRevokeBizClientData + 15, // 50: user.User.InternalDeleteUser:output_type -> user.InternalDeleteUserData + 23, // 51: user.User.InternalGetUserInfo:output_type -> user.InternalGetUserInfoData + 25, // 52: user.User.InternalVerifyPassword:output_type -> user.InternalVerifyPasswordData + 28, // 53: user.User.InternalUsersByBiz:output_type -> user.InternalUsersByBizData + 30, // 54: user.User.InternalLoginByUserId:output_type -> user.InternalLoginByUserIdData + 29, // [29:55] is the sub-list for method output_type + 3, // [3:29] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name 3, // [3:3] is the sub-list for extension extendee 0, // [0:3] is the sub-list for field type_name @@ -2868,7 +2909,7 @@ func file_user_user_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_user_proto_rawDesc), len(file_user_user_proto_rawDesc)), NumEnums: 0, - NumMessages: 41, + NumMessages: 42, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/user/pb/user_grpc.pb.go b/rpc/user/pb/user_grpc.pb.go index a135544..2a82b18 100644 --- a/rpc/user/pb/user_grpc.pb.go +++ b/rpc/user/pb/user_grpc.pb.go @@ -20,6 +20,7 @@ const _ = grpc.SupportPackageIsVersion9 const ( User_Login_FullMethodName = "/user.User/Login" + User_Logout_FullMethodName = "/user.User/Logout" User_GenerateQrcode_FullMethodName = "/user.User/GenerateQrcode" User_QrcodeScan_FullMethodName = "/user.User/QrcodeScan" User_QrcodeLogin_FullMethodName = "/user.User/QrcodeLogin" @@ -51,6 +52,7 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type UserClient interface { Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*Response, error) + Logout(ctx context.Context, in *LogoutReq, opts ...grpc.CallOption) (*Response, error) GenerateQrcode(ctx context.Context, in *GenerateQrcodeReq, opts ...grpc.CallOption) (*Response, error) QrcodeScan(ctx context.Context, in *QrcodeScanReq, opts ...grpc.CallOption) (*Response, error) QrcodeLogin(ctx context.Context, in *QrcodeLoginReq, opts ...grpc.CallOption) (*Response, error) @@ -95,6 +97,16 @@ func (c *userClient) Login(ctx context.Context, in *LoginReq, opts ...grpc.CallO return out, nil } +func (c *userClient) Logout(ctx context.Context, in *LogoutReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, User_Logout_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *userClient) GenerateQrcode(ctx context.Context, in *GenerateQrcodeReq, opts ...grpc.CallOption) (*Response, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Response) @@ -340,6 +352,7 @@ func (c *userClient) InternalLoginByUserId(ctx context.Context, in *InternalLogi // for forward compatibility. type UserServer interface { Login(context.Context, *LoginReq) (*Response, error) + Logout(context.Context, *LogoutReq) (*Response, error) GenerateQrcode(context.Context, *GenerateQrcodeReq) (*Response, error) QrcodeScan(context.Context, *QrcodeScanReq) (*Response, error) QrcodeLogin(context.Context, *QrcodeLoginReq) (*Response, error) @@ -377,6 +390,9 @@ type UnimplementedUserServer struct{} func (UnimplementedUserServer) Login(context.Context, *LoginReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method Login not implemented") } +func (UnimplementedUserServer) Logout(context.Context, *LogoutReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Logout not implemented") +} func (UnimplementedUserServer) GenerateQrcode(context.Context, *GenerateQrcodeReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method GenerateQrcode not implemented") } @@ -488,6 +504,24 @@ func _User_Login_Handler(srv interface{}, ctx context.Context, dec func(interfac return interceptor(ctx, in, info, handler) } +func _User_Logout_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LogoutReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServer).Logout(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: User_Logout_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServer).Logout(ctx, req.(*LogoutReq)) + } + return interceptor(ctx, in, info, handler) +} + func _User_GenerateQrcode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(GenerateQrcodeReq) if err := dec(in); err != nil { @@ -931,6 +965,10 @@ var User_ServiceDesc = grpc.ServiceDesc{ MethodName: "Login", Handler: _User_Login_Handler, }, + { + MethodName: "Logout", + Handler: _User_Logout_Handler, + }, { MethodName: "GenerateQrcode", Handler: _User_GenerateQrcode_Handler, diff --git a/rpc/user/user.pb b/rpc/user/user.pb index 9ee532e987803ba3261ed69c87be9c3a715e2234..b91f764eb636d615cc991fccc701942abdff3ab5 100644 GIT binary patch delta 81 zcmeC3%lLFI;|3>FriI3vT}(OoIk~wwee%=uOG_4ex-c=mp6uloAnwV<1`!kD*DEbf aEz*PVCLeSYnJnxn#+C!tuz8x>cXj|h3mc*U delta 33 pcmaDlm$7#);|3>FrjtgST}(OoH%GbrVPsq|IovH^^C!2@>;T_i4Ql`Z diff --git a/rpc/user/user.proto b/rpc/user/user.proto index 91e7146..d918a1a 100644 --- a/rpc/user/user.proto +++ b/rpc/user/user.proto @@ -12,6 +12,12 @@ service User { body: "*" }; } + rpc Logout(LogoutReq) returns (Response) { + option (google.api.http) = { + post: "/api/v3/user/logout" + body: "*" + }; + } rpc GenerateQrcode(GenerateQrcodeReq) returns (Response) { option (google.api.http) = { post: "/api/v3/user/qrcode/generate" @@ -316,6 +322,8 @@ message RebindMobileReq { message InfoReq {} +message LogoutReq {} + message UpdateReq { string name = 1; string avatar = 2; diff --git a/services/analysis/internal/logic/analysisuser/userStatusLogic.go b/services/analysis/internal/logic/analysisuser/userStatusLogic.go index 7ff7806..2ce80ea 100644 --- a/services/analysis/internal/logic/analysisuser/userStatusLogic.go +++ b/services/analysis/internal/logic/analysisuser/userStatusLogic.go @@ -67,9 +67,6 @@ func (l *UserStatusLogic) syncRegisteredFromUser(bizId, userId int64, isRegister if isRegistered != uint8(utils.StatusFail) { return isRegistered } - if userId < utils.NumberOne || l.svcCtx.UserSvcName == utils.StringEmpty { - return isRegistered - } cli, err := svc.GetRpcClient(l.svcCtx.UserSvcName) if err != nil { diff --git a/services/user/internal/logic/logoutLogic.go b/services/user/internal/logic/logoutLogic.go new file mode 100644 index 0000000..e6d3ae1 --- /dev/null +++ b/services/user/internal/logic/logoutLogic.go @@ -0,0 +1,87 @@ +package logic + +import ( + "context" + "strconv" + + "lone-services/pkg/redis" + "lone-services/pkg/utils" + user "lone-services/rpc/user/pb" + "lone-services/services/user/internal/dao" + "lone-services/services/user/internal/svc" + + jsoniter "github.com/json-iterator/go" + "github.com/zeromicro/go-zero/core/logx" +) + +type LogoutLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic { + return &LogoutLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *LogoutLogic) Logout(in *user.LogoutReq) (*user.Response, error) { + loginUser := utils.GetUserFromCtx(l.ctx) + if loginUser.ID < utils.NumberOne { + return failResponse(utils.ErrorNoLoginInfo), nil + } + + loginType, typeErr := resolveLoginCacheType(loginUser) + if typeErr != nil { + l.Errorf("logout resolve login type: %v", typeErr) + return failResponse(utils.Fail), nil + } + if loginType == utils.StringEmpty { + return outResponse(utils.ErrorParams, "无法识别登录类型"), nil + } + + redisKeysKey := utils.GetLoginKeysKey(loginType, strconv.FormatInt(loginUser.ID, utils.NumberTen)) + oldAuth, oldErr := redis.Client.Get(l.ctx, redisKeysKey).Result() + if oldErr != nil { + return failResponse(utils.ErrorNoLoginInfo), nil + } + + var loginInfo utils.LoginRedis + if err := jsoniter.Unmarshal([]byte(oldAuth), &loginInfo); err != nil { + return failResponse(utils.ErrorNoLoginInfo), nil + } + + if len(loginInfo.Token) > utils.NumberOne { + _ = redis.Client.Del(l.ctx, utils.GetLoginKey(loginType, loginInfo.Token)).Err() + } + if len(loginInfo.Refresh) > utils.NumberOne { + _ = redis.Client.Del(l.ctx, utils.GetLoginRefreshKey(loginType, loginInfo.Refresh)).Err() + } + _ = redis.Client.Del(l.ctx, redisKeysKey).Err() + + return okResponse(utils.NumberOne), nil +} + +func resolveLoginCacheType(loginUser utils.UserInfo) (string, error) { + if loginUser.ClientCode != utils.StringEmpty { + client, err := loadEnabledClient(loginUser.ClientCode) + if err != nil { + return utils.StringEmpty, err + } + return loginCacheType(client), nil + } + + switch loginUser.Type { + case dao.TypeSale: + return utils.LoginTypeSale, nil + case dao.TypeStore: + return utils.LoginTypeStore, nil + case dao.TypeUser: + return utils.LoginTypeUser, nil + default: + return utils.StringEmpty, nil + } +} diff --git a/services/user/internal/server/userServer.go b/services/user/internal/server/userServer.go index 84fbb11..e5fd500 100644 --- a/services/user/internal/server/userServer.go +++ b/services/user/internal/server/userServer.go @@ -28,6 +28,11 @@ func (s *UserServer) Login(ctx context.Context, in *user.LoginReq) (*user.Respon return l.Login(in) } +func (s *UserServer) Logout(ctx context.Context, in *user.LogoutReq) (*user.Response, error) { + l := logic.NewLogoutLogic(ctx, s.svcCtx) + return l.Logout(in) +} + func (s *UserServer) GenerateQrcode(ctx context.Context, in *user.GenerateQrcodeReq) (*user.Response, error) { l := logic.NewGenerateQrcodeLogic(ctx, s.svcCtx) return l.GenerateQrcode(in) diff --git a/services/user/userClient/user.go b/services/user/userClient/user.go index e6227ac..ed54b93 100644 --- a/services/user/userClient/user.go +++ b/services/user/userClient/user.go @@ -46,6 +46,7 @@ type ( InternalVerifyPasswordData = user.InternalVerifyPasswordData InternalVerifyPasswordReq = user.InternalVerifyPasswordReq LoginReq = user.LoginReq + LogoutReq = user.LogoutReq PasswordReq = user.PasswordReq QrcodeLoginReq = user.QrcodeLoginReq QrcodeScanReq = user.QrcodeScanReq @@ -58,6 +59,7 @@ type ( User interface { Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*Response, error) + Logout(ctx context.Context, in *LogoutReq, opts ...grpc.CallOption) (*Response, error) GenerateQrcode(ctx context.Context, in *GenerateQrcodeReq, opts ...grpc.CallOption) (*Response, error) QrcodeScan(ctx context.Context, in *QrcodeScanReq, opts ...grpc.CallOption) (*Response, error) QrcodeLogin(ctx context.Context, in *QrcodeLoginReq, opts ...grpc.CallOption) (*Response, error) @@ -100,6 +102,11 @@ func (m *defaultUser) Login(ctx context.Context, in *LoginReq, opts ...grpc.Call return client.Login(ctx, in, opts...) } +func (m *defaultUser) Logout(ctx context.Context, in *LogoutReq, opts ...grpc.CallOption) (*Response, error) { + client := user.NewUserClient(m.cli.Conn()) + return client.Logout(ctx, in, opts...) +} + func (m *defaultUser) GenerateQrcode(ctx context.Context, in *GenerateQrcodeReq, opts ...grpc.CallOption) (*Response, error) { client := user.NewUserClient(m.cli.Conn()) return client.GenerateQrcode(ctx, in, opts...)