zrufo 4 лет назад
Родитель
Сommit
f2fb1c8dd8

+ 1 - 1
api/grpc/base.go

@@ -41,7 +41,7 @@ func (Api) getToken(ctx context.Context) (token string) {
 
 func (a Api) SignIn(ctx context.Context, q *pb.SignInRequest) (*pb.SignInReply, error) {
 	token := service.User{}.SignInUserCodePassword(
-		q.Name, q.Password, a.getRemoteIp(ctx), a.getUserAgent(ctx))
+		q.Name, q.Password, a.getRemoteIp(ctx), a.getUserAgent(ctx), q.CodeId, q.VerifyCode)
 
 	return &pb.SignInReply{Token: token}, nil
 }

+ 37 - 17
api/grpc/base/base.pb.go

@@ -251,8 +251,10 @@ type SignInRequest struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Name     string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
-	Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
+	Name       string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+	Password   string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
+	CodeId     string `protobuf:"bytes,3,opt,name=codeId,proto3" json:"codeId,omitempty"`
+	VerifyCode string `protobuf:"bytes,4,opt,name=verifyCode,proto3" json:"verifyCode,omitempty"`
 }
 
 func (x *SignInRequest) Reset() {
@@ -301,6 +303,20 @@ func (x *SignInRequest) GetPassword() string {
 	return ""
 }
 
+func (x *SignInRequest) GetCodeId() string {
+	if x != nil {
+		return x.CodeId
+	}
+	return ""
+}
+
+func (x *SignInRequest) GetVerifyCode() string {
+	if x != nil {
+		return x.VerifyCode
+	}
+	return ""
+}
+
 var File_base_proto protoreflect.FileDescriptor
 
 var file_base_proto_rawDesc = []byte{
@@ -313,24 +329,28 @@ var file_base_proto_rawDesc = []byte{
 	0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73,
 	0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x23, 0x0a, 0x0b, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x52,
 	0x65, 0x70, 0x6c, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20,
-	0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x3f, 0x0a, 0x0d, 0x53, 0x69,
+	0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x77, 0x0a, 0x0d, 0x53, 0x69,
 	0x67, 0x6e, 0x49, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e,
 	0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12,
 	0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
-	0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x2a, 0x13, 0x0a, 0x09, 0x45,
-	0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x4b, 0x10, 0x00,
-	0x32, 0xa5, 0x01, 0x0a, 0x03, 0x41, 0x70, 0x69, 0x12, 0x33, 0x0a, 0x06, 0x53, 0x69, 0x67, 0x6e,
-	0x55, 0x70, 0x12, 0x13, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x55, 0x70,
-	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x44,
-	0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x32, 0x0a,
-	0x06, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x12, 0x13, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x53,
-	0x69, 0x67, 0x6e, 0x49, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x62,
-	0x61, 0x73, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22,
-	0x00, 0x12, 0x35, 0x0a, 0x07, 0x53, 0x69, 0x67, 0x6e, 0x4f, 0x75, 0x74, 0x12, 0x14, 0x2e, 0x62,
-	0x61, 0x73, 0x65, 0x2e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
-	0x73, 0x74, 0x1a, 0x12, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c,
-	0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x3b, 0x62, 0x61,
-	0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x63,
+	0x6f, 0x64, 0x65, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6f, 0x64,
+	0x65, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64,
+	0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43,
+	0x6f, 0x64, 0x65, 0x2a, 0x13, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65,
+	0x12, 0x06, 0x0a, 0x02, 0x4f, 0x4b, 0x10, 0x00, 0x32, 0xa5, 0x01, 0x0a, 0x03, 0x41, 0x70, 0x69,
+	0x12, 0x33, 0x0a, 0x06, 0x53, 0x69, 0x67, 0x6e, 0x55, 0x70, 0x12, 0x13, 0x2e, 0x62, 0x61, 0x73,
+	0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x55, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
+	0x12, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65,
+	0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x32, 0x0a, 0x06, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x12,
+	0x13, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x52, 0x65, 0x71,
+	0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e,
+	0x49, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x07, 0x53, 0x69, 0x67,
+	0x6e, 0x4f, 0x75, 0x74, 0x12, 0x14, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x44, 0x65, 0x66, 0x61,
+	0x75, 0x6c, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x62, 0x61, 0x73,
+	0x65, 0x2e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00,
+	0x42, 0x08, 0x5a, 0x06, 0x2e, 0x3b, 0x62, 0x61, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
+	0x6f, 0x33,
 }
 
 var (

+ 4 - 2
assembly/base/service/user.go

@@ -6,9 +6,11 @@ type User struct {
 	base
 }
 
-func (User) SignInUserCodePassword(userCode, password, ip, ClientInfo string) (token string) {
+func (User) SignInUserCodePassword(userCode, password, ip, ClientInfo,
+	codeId, verifyCode string) (token string) {
 
-	token, userId := im.SignInUserCodePassword(userCode, password, ip, ClientInfo)
+	token, userId := im.SignInUserCodePassword(userCode, password, ip, ClientInfo,
+		codeId, verifyCode)
 
 	println(token, userId)
 

+ 22 - 6
proto/client/bsw/im/im.proto

@@ -10,10 +10,13 @@ enum ErrorCode{
   PARAM = 4001;
   Exist = 4002;
   Token = 4003;
+  PasswordWrongTooMuch = 4004;
+  VerifyCode = 4005;
 }
 
 // metadata: 综合管理系统前端调用需要字段 token 用作登录验证;子系统调用需要字段 sys_token 用作系统验证
 service Api {
+  rpc GenVerifyImage(GenVerifyImageRequest)returns(GenVerifyImageReply){}
   rpc SignUpUserCode (SignUpRequest) returns (CreateReply) {}
   rpc SignUpPhone (SignUpRequest) returns (CreateReply) {}
 
@@ -95,6 +98,17 @@ service Api {
 }
 message DefaultRequest{
 }
+
+message GenVerifyImageRequest{
+  int32 height = 1;
+  int32 width = 2;
+}
+message GenVerifyImageReply{
+  string codeId = 1;
+  string imageBase64 = 2;
+}
+
+
 message TokenParam{
   string token = 1;
 }
@@ -109,15 +123,17 @@ message CreateReply{
 }
 
 message SignInPasswordRequest {
+  string codeId = 1;
+  string verifyCode = 2;
   //登录凭据,用户名、手机号等
-  string credential = 1;
-  string password = 2;
+  string credential = 3;
+  string password = 4;
   //仅综合管理后台有效
-  int64 sysId = 3;
+  int64 sysId = 5;
   //session有效期,单位:秒
-  int64 expirationSec = 4;
-  string ip = 5;
-  string clientInfo = 6;
+  int64 expirationSec = 6;
+  string ip = 7;
+  string clientInfo = 8;
 }
 
 enum Status{

+ 2 - 0
proto/server/base.proto

@@ -30,4 +30,6 @@ message SignInReply {
 message SignInRequest {
   string name = 1;
   string password = 2;
+  string codeId = 3;
+  string verifyCode = 4;
 }

+ 18 - 1
repository/grpc/bsw/im/api.go

@@ -32,13 +32,30 @@ func SignUpUserCode(params *pb.SignUpRequest) (userId int64) {
 	userId = r.GetId()
 	return
 }
-func SignInUserCodePassword(userCode, password, ip, ClientInfo string) (token string, userId int) {
+
+func GenVerifyImage(height, width int) (id, imageBase64 string) {
+	r, err := getClient().GenVerifyImage(ctx(), &pb.GenVerifyImageRequest{
+		Height: int32(height),
+		Width:  int32(width),
+	})
+	if err != nil {
+		panic(err)
+	}
+
+	id = r.CodeId
+	imageBase64 = r.ImageBase64
+	return
+}
+
+func SignInUserCodePassword(userCode, password, ip, ClientInfo, codeId, verifyCode string) (token string, userId int) {
 	r, err := getClient().SignInUserCode(ctx(), &pb.SignInPasswordRequest{
 		Credential:    userCode,
 		Password:      password,
 		ExpirationSec: global.TokenExpireSec,
 		Ip:            ip,
 		ClientInfo:    ClientInfo,
+		CodeId:        codeId,
+		VerifyCode:    verifyCode,
 	})
 	if err != nil {
 		panic(err)

Разница между файлами не показана из-за своего большого размера
+ 236 - 104
repository/grpc/bsw/im/im/im.pb.go


+ 36 - 0
repository/grpc/bsw/im/im/im_grpc.pb.go

@@ -17,6 +17,7 @@ const _ = grpc.SupportPackageIsVersion7
 //
 // 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 ApiClient interface {
+	GenVerifyImage(ctx context.Context, in *GenVerifyImageRequest, opts ...grpc.CallOption) (*GenVerifyImageReply, error)
 	SignUpUserCode(ctx context.Context, in *SignUpRequest, opts ...grpc.CallOption) (*CreateReply, error)
 	SignUpPhone(ctx context.Context, in *SignUpRequest, opts ...grpc.CallOption) (*CreateReply, error)
 	SignInUserCode(ctx context.Context, in *SignInPasswordRequest, opts ...grpc.CallOption) (*SignInReply, error)
@@ -85,6 +86,15 @@ func NewApiClient(cc grpc.ClientConnInterface) ApiClient {
 	return &apiClient{cc}
 }
 
+func (c *apiClient) GenVerifyImage(ctx context.Context, in *GenVerifyImageRequest, opts ...grpc.CallOption) (*GenVerifyImageReply, error) {
+	out := new(GenVerifyImageReply)
+	err := c.cc.Invoke(ctx, "/im.Api/GenVerifyImage", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 func (c *apiClient) SignUpUserCode(ctx context.Context, in *SignUpRequest, opts ...grpc.CallOption) (*CreateReply, error) {
 	out := new(CreateReply)
 	err := c.cc.Invoke(ctx, "/im.Api/SignUpUserCode", in, out, opts...)
@@ -409,6 +419,7 @@ func (x *apiIMMessageRcvClient) Recv() (*Message, error) {
 // All implementations must embed UnimplementedApiServer
 // for forward compatibility
 type ApiServer interface {
+	GenVerifyImage(context.Context, *GenVerifyImageRequest) (*GenVerifyImageReply, error)
 	SignUpUserCode(context.Context, *SignUpRequest) (*CreateReply, error)
 	SignUpPhone(context.Context, *SignUpRequest) (*CreateReply, error)
 	SignInUserCode(context.Context, *SignInPasswordRequest) (*SignInReply, error)
@@ -474,6 +485,9 @@ type ApiServer interface {
 type UnimplementedApiServer struct {
 }
 
+func (UnimplementedApiServer) GenVerifyImage(context.Context, *GenVerifyImageRequest) (*GenVerifyImageReply, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method GenVerifyImage not implemented")
+}
 func (UnimplementedApiServer) SignUpUserCode(context.Context, *SignUpRequest) (*CreateReply, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method SignUpUserCode not implemented")
 }
@@ -586,6 +600,24 @@ func RegisterApiServer(s grpc.ServiceRegistrar, srv ApiServer) {
 	s.RegisterService(&_Api_serviceDesc, srv)
 }
 
+func _Api_GenVerifyImage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(GenVerifyImageRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ApiServer).GenVerifyImage(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/im.Api/GenVerifyImage",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ApiServer).GenVerifyImage(ctx, req.(*GenVerifyImageRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 func _Api_SignUpUserCode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 	in := new(SignUpRequest)
 	if err := dec(in); err != nil {
@@ -1187,6 +1219,10 @@ var _Api_serviceDesc = grpc.ServiceDesc{
 	ServiceName: "im.Api",
 	HandlerType: (*ApiServer)(nil),
 	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "GenVerifyImage",
+			Handler:    _Api_GenVerifyImage_Handler,
+		},
 		{
 			MethodName: "SignUpUserCode",
 			Handler:    _Api_SignUpUserCode_Handler,

Некоторые файлы не были показаны из-за большого количества измененных файлов