Skip to content

Commit

Permalink
added team update pass and get event id
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmet Turkmen <[email protected]>
  • Loading branch information
mrtrkmn committed Apr 16, 2021
1 parent d4afb00 commit baad7de
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions database/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (

UpdateEventLastaccessedDate = "UPDATE team SET last_access = $2 WHERE tag = $1"
UpdateTeamSolvedChl = "UPDATE team SET solved_challenges = $2 WHERE tag = $1"
UpdateTeamPassword = "UPDATE team SET password = $1 WHERE tag = $2 and event_id = $3"

QuerySolvedChls = "SELECT solved_challenges FROM team WHERE tag=$1"
QueryEventTable = "SELECT * FROM event"
Expand Down
19 changes: 19 additions & 0 deletions database/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Store interface {
SetEventStatus(*pb.SetEventStatusRequest) (int32, error)
UpdateTeamSolvedChallenge(*pb.UpdateTeamSolvedChallengeRequest) (string, error)
UpdateTeamLastAccess(*pb.UpdateTeamLastAccessRequest) (string, error)
UpdateTeamPassword(in *pb.UpdateTeamPassRequest) error
GetEventID(in *pb.GetEventIDReq) (int32, error)
UpdateCloseEvent(*pb.UpdateEventRequest) (string, error)
}

Expand Down Expand Up @@ -243,6 +245,23 @@ func (s *store) UpdateTeamSolvedChallenge(in *pb.UpdateTeamSolvedChallengeReques
return OK, nil
}

func (s *store) UpdateTeamPassword(in *pb.UpdateTeamPassRequest) error {
_, err := s.db.Exec(UpdateTeamPassword, in.EncryptedPass, in.TeamID, in.EventID)
if err != nil {
return err
}
return nil
}

func (s *store) GetEventID(in *pb.GetEventIDReq) (int32, error) {

var eventId int32
if err := s.db.QueryRow(QueryEventId, in.EventTag).Scan(&eventId); err != nil && !strings.Contains(err.Error(), "no rows in result set") {
return -1, err
}
return eventId, nil
}

func (s *store) UpdateTeamLastAccess(in *pb.UpdateTeamLastAccessRequest) (string, error) {
s.m.Lock()
defer s.m.Unlock()
Expand Down
18 changes: 18 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ func (s server) UpdateTeamLastAccess(ctx context.Context, in *pb.UpdateTeamLastA
return &pb.UpdateResponse{Message: result}, nil
}

func (s server) UpdateTeamPassword(ctx context.Context, req *pb.UpdateTeamPassRequest) (*pb.UpdateResponse, error) {
if err := s.store.UpdateTeamPassword(req); err != nil {
log.Printf("ERR: Error Update team %s password: %s", req.TeamID, err.Error())
return &pb.UpdateResponse{ErrorMessage: err.Error()}, err
}

return &pb.UpdateResponse{}, nil
}

func (s server) GetEventID(ctx context.Context, req *pb.GetEventIDReq) (*pb.GetEventIDResp, error) {
id, err := s.store.GetEventID(req)
if err != nil {
return &pb.GetEventIDResp{}, err
}

return &pb.GetEventIDResp{EventID: id}, nil
}

func GetCreds(conf *model.Config) (credentials.TransportCredentials, error) {
log.Printf("Preparing credentials for RPC")

Expand Down

0 comments on commit baad7de

Please sign in to comment.