frontend: public part now validate through blake2b.js flags and MCQs
This commit is contained in:
parent
8ac2776cca
commit
5c742834ea
5 changed files with 2675 additions and 37 deletions
|
|
@ -26,23 +26,25 @@ type myTeamMCQ struct {
|
|||
Justify bool `json:"justify,omitempty"`
|
||||
Choices map[int64]string `json:"choices,omitempty"`
|
||||
Solved *time.Time `json:"solved,omitempty"`
|
||||
Soluce string `json:"soluce,omitempty"`
|
||||
}
|
||||
type myTeamFlag struct {
|
||||
Label string `json:"label"`
|
||||
Help string `json:"help,omitempty"`
|
||||
Solved *time.Time `json:"found,omitempty"`
|
||||
Soluce []byte `json:"soluce,omitempty"`
|
||||
Soluce string `json:"soluce,omitempty"`
|
||||
}
|
||||
type myTeamExercice struct {
|
||||
ThemeId int `json:"theme_id"`
|
||||
Statement string `json:"statement"`
|
||||
Overview string `json:"overview,omitempty"`
|
||||
Hints []myTeamHint `json:"hints,omitempty"`
|
||||
Gain int `json:"gain"`
|
||||
Files []myTeamFile `json:"files,omitempty"`
|
||||
Flags map[int64]myTeamFlag `json:"flags,omitempty"`
|
||||
MCQs map[int64]myTeamMCQ `json:"mcqs,omitempty"`
|
||||
SolveDist int64 `json:"solve_dist,omitempty"`
|
||||
SolvedTime time.Time `json:"solved_time,omitempty"`
|
||||
SolvedTime *time.Time `json:"solved_time,omitempty"`
|
||||
SolvedRank int64 `json:"solved_rank,omitempty"`
|
||||
Tries int64 `json:"tries,omitempty"`
|
||||
VideoURI string `json:"video_uri,omitempty"`
|
||||
|
|
@ -94,22 +96,20 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
}
|
||||
|
||||
if t == nil {
|
||||
if e.Overview != "" {
|
||||
exercice.Statement = e.Overview
|
||||
}
|
||||
exercice.Overview = e.Overview
|
||||
exercice.VideoURI = e.VideoURI
|
||||
exercice.SolvedRank = 1
|
||||
exercice.Tries = e.TriedCount()
|
||||
exercice.Gain = int(float64(e.Gain) * e.Coefficient)
|
||||
} else {
|
||||
var solved bool
|
||||
solved, exercice.SolvedTime = t.HasSolved(e)
|
||||
solved, stime := t.HasSolved(e)
|
||||
exercice.SolvedTime = &stime
|
||||
exercice.SolvedRank, _ = t.GetSolvedRank(e)
|
||||
|
||||
if solved {
|
||||
exercice.Tries, _ = t.CountTries(e)
|
||||
} else {
|
||||
exercice.Tries, exercice.SolvedTime = t.CountTries(e)
|
||||
exercice.Tries, stime = t.CountTries(e)
|
||||
exercice.SolvedTime = &stime
|
||||
if exercice.Tries > 0 {
|
||||
exercice.SolveDist = t.LastTryDist(e)
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
|
||||
// Expose exercice flags
|
||||
|
||||
var justifiedMCQ map[string]bool
|
||||
var justifiedMCQ map[string][]byte
|
||||
exercice.Flags = map[int64]myTeamFlag{}
|
||||
|
||||
if flags, err := e.GetFlags(); err != nil {
|
||||
|
|
@ -164,10 +164,10 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
var flag myTeamFlag
|
||||
|
||||
if k.Label[0] == '%' {
|
||||
justifiedMCQ[k.Label[1:]] = true
|
||||
justifiedMCQ[k.Label[1:]] = k.Checksum
|
||||
continue
|
||||
} else if t == nil {
|
||||
flag.Soluce = k.Checksum
|
||||
flag.Soluce = hex.EncodeToString(k.Checksum)
|
||||
} else if PartialValidation {
|
||||
flag.Solved = t.HasPartiallySolved(k)
|
||||
}
|
||||
|
|
@ -187,19 +187,33 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
return nil, err
|
||||
} else {
|
||||
for _, mcq := range mcqs {
|
||||
choices := map[int64]string{}
|
||||
justified := false
|
||||
m := myTeamMCQ{
|
||||
Title: mcq.Title,
|
||||
Choices: map[int64]string{},
|
||||
}
|
||||
|
||||
soluce := ""
|
||||
|
||||
for _, e := range mcq.Entries {
|
||||
choices[e.Id] = e.Label
|
||||
if _, ok := justifiedMCQ[m.Title + "%" + e.Label]; ok {
|
||||
justified = true
|
||||
m.Choices[e.Id] = e.Label
|
||||
if e.Response {
|
||||
soluce += "t"
|
||||
} else {
|
||||
soluce += "f"
|
||||
}
|
||||
if v, ok := justifiedMCQ[m.Title + "%" + e.Label]; ok {
|
||||
m.Justify = true
|
||||
if t == nil {
|
||||
soluce += hex.EncodeToString(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m := myTeamMCQ{mcq.Title, justified, choices, nil}
|
||||
|
||||
if t != nil {
|
||||
m.Solved = t.HasPartiallyRespond(mcq)
|
||||
} else {
|
||||
h := getHashedFlag([]byte(soluce))
|
||||
m.Soluce = hex.EncodeToString(h[:])
|
||||
}
|
||||
|
||||
exercice.MCQs[mcq.Id] = m
|
||||
|
|
|
|||
Reference in a new issue