From 7de3a6324f0e7452d14bf3def70f432fda523ddc Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Tue, 20 May 2025 02:04:13 +0700 Subject: [PATCH] fix login --- api/main.proto | 8 +++-- internal/services/mappers.go | 5 +-- internal/services/repository.go | 5 --- internal/services/services.go | 11 +++++-- proto/main.pb.go | 55 ++++++++++++++++++++++----------- proto/main.swagger.json | 6 ++++ 6 files changed, 60 insertions(+), 30 deletions(-) diff --git a/api/main.proto b/api/main.proto index b8f4192..d6e7d0e 100644 --- a/api/main.proto +++ b/api/main.proto @@ -104,8 +104,9 @@ message GetTeamsCSVRsp { message TeamAdvanced { int64 id = 1; string name = 2; - int64 spendTime = 3; - repeated Application applications = 4; + string password = 3; + int64 spendTime = 4; + repeated Application applications = 5; } message Application { @@ -117,7 +118,8 @@ message Application { message GetTeamReq {} message GetTeamRsp { - repeated Action actions = 1; + string name = 1; + repeated Action actions = 2; } message AddActionReq { diff --git a/internal/services/mappers.go b/internal/services/mappers.go index c4b0c5a..248a123 100644 --- a/internal/services/mappers.go +++ b/internal/services/mappers.go @@ -8,8 +8,9 @@ import ( func mapTeamsToTeamAdvanced(team *models.Team) *proto.TeamAdvanced { return &proto.TeamAdvanced{ - Id: team.ID, - Name: team.Name, + Id: team.ID, + Name: team.Name, + Password: team.Password, } } diff --git a/internal/services/repository.go b/internal/services/repository.go index 6795e4e..ca990ac 100644 --- a/internal/services/repository.go +++ b/internal/services/repository.go @@ -30,11 +30,6 @@ func NewRepository() (*Repository, error) { if err != nil { return nil, err } - // for tests - // _, err = db.Exec("insert into teams (id, name, password) values (1, \"name\", \"pass\");") - // if err != nil { - // return nil, err - // } return &Repository{db: db}, nil } diff --git a/internal/services/services.go b/internal/services/services.go index 0bae8cf..37cf17c 100644 --- a/internal/services/services.go +++ b/internal/services/services.go @@ -2,6 +2,7 @@ package services import ( "context" + "encoding/base64" "encoding/json" "evening_detective/internal/models" "evening_detective/internal/modules/password" @@ -96,7 +97,10 @@ func (s *Services) GetTeam(ctx context.Context, req *proto.GetTeamReq) (*proto.G } res = append(res, newAction) } - return &proto.GetTeamRsp{Actions: res}, err + return &proto.GetTeamRsp{ + Name: team.Name, + Actions: res, + }, err } func (s *Services) GetTeamsCSV(ctx context.Context, req *proto.GetTeamsCSVReq) (*proto.GetTeamsCSVRsp, error) { @@ -154,7 +158,10 @@ func (s *Services) getTeam(ctx context.Context) (*models.Team, error) { if !ok { return nil, status.Errorf(codes.Unauthenticated, "error creds") } - teamId := teamIdArr[0] + teamId, err := base64.StdEncoding.DecodeString(teamIdArr[0]) + if err != nil { + return nil, status.Errorf(codes.Unauthenticated, "error creds") + } passwordArr, ok := md["password"] if !ok { diff --git a/proto/main.pb.go b/proto/main.pb.go index 8da1567..7bd7b16 100644 --- a/proto/main.pb.go +++ b/proto/main.pb.go @@ -478,8 +478,9 @@ type TeamAdvanced struct { Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - SpendTime int64 `protobuf:"varint,3,opt,name=spendTime,proto3" json:"spendTime,omitempty"` - Applications []*Application `protobuf:"bytes,4,rep,name=applications,proto3" json:"applications,omitempty"` + Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"` + SpendTime int64 `protobuf:"varint,4,opt,name=spendTime,proto3" json:"spendTime,omitempty"` + Applications []*Application `protobuf:"bytes,5,rep,name=applications,proto3" json:"applications,omitempty"` } func (x *TeamAdvanced) Reset() { @@ -528,6 +529,13 @@ func (x *TeamAdvanced) GetName() string { return "" } +func (x *TeamAdvanced) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + func (x *TeamAdvanced) GetSpendTime() int64 { if x != nil { return x.SpendTime @@ -648,7 +656,8 @@ type GetTeamRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Actions []*Action `protobuf:"bytes,1,rep,name=actions,proto3" json:"actions,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Actions []*Action `protobuf:"bytes,2,rep,name=actions,proto3" json:"actions,omitempty"` } func (x *GetTeamRsp) Reset() { @@ -683,6 +692,13 @@ func (*GetTeamRsp) Descriptor() ([]byte, []int) { return file_main_proto_rawDescGZIP(), []int{13} } +func (x *GetTeamRsp) GetName() string { + if x != nil { + return x.Name + } + return "" +} + func (x *GetTeamRsp) GetActions() []*Action { if x != nil { return x.Actions @@ -1141,23 +1157,26 @@ var file_main_proto_rawDesc = []byte{ 0x65, 0x61, 0x6d, 0x73, 0x43, 0x53, 0x56, 0x52, 0x65, 0x71, 0x22, 0x24, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x54, 0x65, 0x61, 0x6d, 0x73, 0x43, 0x53, 0x56, 0x52, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x22, 0x9a, 0x01, 0x0a, 0x0c, 0x54, 0x65, 0x61, 0x6d, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, + 0x22, 0xb6, 0x01, 0x0a, 0x0c, 0x54, 0x65, 0x61, 0x6d, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x70, 0x65, 0x6e, 0x64, 0x54, 0x69, - 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x73, 0x70, 0x65, 0x6e, 0x64, 0x54, - 0x69, 0x6d, 0x65, 0x12, 0x48, 0x0a, 0x0c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x72, 0x61, 0x62, - 0x73, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, - 0x69, 0x76, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x0c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x47, 0x0a, - 0x0b, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x0c, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x54, 0x65, 0x61, - 0x6d, 0x52, 0x65, 0x71, 0x22, 0x47, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x54, 0x65, 0x61, 0x6d, 0x52, - 0x73, 0x70, 0x12, 0x39, 0x0a, 0x07, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, + 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, + 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x70, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x73, 0x70, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, + 0x48, 0x0a, 0x0c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, + 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x65, 0x76, + 0x65, 0x6e, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x2e, + 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x61, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x47, 0x0a, 0x0b, 0x41, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, + 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x22, 0x0c, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x54, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, + 0x22, 0x5b, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x54, 0x65, 0x61, 0x6d, 0x52, 0x73, 0x70, 0x12, 0x12, + 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x39, 0x0a, 0x07, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x24, 0x0a, diff --git a/proto/main.swagger.json b/proto/main.swagger.json index d10ca3f..3bb5013 100644 --- a/proto/main.swagger.json +++ b/proto/main.swagger.json @@ -359,6 +359,9 @@ "evening_detectiveGetTeamRsp": { "type": "object", "properties": { + "name": { + "type": "string" + }, "actions": { "type": "array", "items": { @@ -425,6 +428,9 @@ "name": { "type": "string" }, + "password": { + "type": "string" + }, "spendTime": { "type": "string", "format": "int64"