diff --git a/admin/api/exercice.go b/admin/api/exercice.go index 69324d71..16ea7fc6 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -113,23 +113,6 @@ func createExercice(theme fic.Theme, body []byte) (interface{}, error) { return theme.AddExercice(ue.Title, ue.Path, ue.Statement, depend, ue.Gain, ue.VideoURI) } -type uploadedKey struct { - Type string - Key string -} - -func createExerciceKey(exercice fic.Exercice, body []byte) (interface{}, error) { - var uk uploadedKey - if err := json.Unmarshal(body, &uk); err != nil { - return nil, err - } - - if len(uk.Key) == 0 { - return nil, errors.New("Key not filled") - } - - return exercice.AddRawKey(uk.Type, uk.Key) -} type uploadedHint struct { Title string @@ -185,28 +168,46 @@ func deleteExerciceHint(hint fic.EHint, _ []byte) (interface{}, error) { } +type uploadedKey struct { + Label string + Key string + Hash []byte +} + +func createExerciceKey(exercice fic.Exercice, body []byte) (interface{}, error) { + var uk uploadedKey + if err := json.Unmarshal(body, &uk); err != nil { + return nil, err + } + + if len(uk.Key) == 0 { + return nil, errors.New("Key not filled") + } + + return exercice.AddRawKey(uk.Label, uk.Key) +} + func showExerciceKey(key fic.Key, _ fic.Exercice, body []byte) (interface{}, error) { return key, nil } func updateExerciceKey(key fic.Key, exercice fic.Exercice, body []byte) (interface{}, error) { - var uk fic.Key + var uk uploadedKey if err := json.Unmarshal(body, &uk); err != nil { return nil, err } - uk.Id = key.Id - uk.IdExercice = exercice.Id - - if len(uk.Type) == 0 { - uk.Type = "Flag" + if len(uk.Label) == 0 { + key.Label = "Flag" + } else { + key.Label = uk.Label } - if _, err := uk.Update(); err != nil { + if _, err := key.Update(); err != nil { return nil, err } - return uk, nil + return key, nil } func deleteExerciceKey(key fic.Key, _ fic.Exercice, _ []byte) (interface{}, error) { diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html index 9197bbd2..e2c86e98 100644 --- a/admin/static/views/exercice.html +++ b/admin/static/views/exercice.html @@ -84,9 +84,9 @@