libfic: Type key is now Label
This commit is contained in:
parent
a1c6eadbe5
commit
9a9d5fcda4
5 changed files with 34 additions and 33 deletions
|
@ -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)
|
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 {
|
type uploadedHint struct {
|
||||||
Title string
|
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) {
|
func showExerciceKey(key fic.Key, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||||
return key, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateExerciceKey(key fic.Key, exercice fic.Exercice, body []byte) (interface{}, error) {
|
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 {
|
if err := json.Unmarshal(body, &uk); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
uk.Id = key.Id
|
if len(uk.Label) == 0 {
|
||||||
uk.IdExercice = exercice.Id
|
key.Label = "Flag"
|
||||||
|
} else {
|
||||||
if len(uk.Type) == 0 {
|
key.Label = uk.Label
|
||||||
uk.Type = "Flag"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := uk.Update(); err != nil {
|
if _, err := key.Update(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return uk, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteExerciceKey(key fic.Key, _ fic.Exercice, _ []byte) (interface{}, error) {
|
func deleteExerciceKey(key fic.Key, _ fic.Exercice, _ []byte) (interface{}, error) {
|
||||||
|
|
|
@ -84,9 +84,9 @@
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
<form ng-submit="saveKey()" class="list-group-item form-horizontal" ng-repeat="key in keys">
|
<form ng-submit="saveKey()" class="list-group-item form-horizontal" ng-repeat="key in keys">
|
||||||
<div class="form-group" id="key-{{key.id}}">
|
<div class="form-group" id="key-{{key.id}}">
|
||||||
<label for="ktype{{key.id}}" class="col-xs-2 control-label">Intitulé</label>
|
<label for="klabel{{key.id}}" class="col-xs-2 control-label">Intitulé</label>
|
||||||
<div class="col-xs-8">
|
<div class="col-xs-8">
|
||||||
<input type="text" id="ktype{{key.id}}" ng-model="key.type" class="form-control">
|
<input type="text" id="klabel{{key.id}}" ng-model="key.type" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-1" ng-show="key.id">
|
<div class="col-xs-1" ng-show="key.id">
|
||||||
<a ng-click="deleteKey()" class="btn btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
|
<a ng-click="deleteKey()" class="btn btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
|
||||||
|
|
|
@ -214,7 +214,7 @@ func (e Exercice) CheckResponse(resps map[string]string, t Team) (bool, error) {
|
||||||
|
|
||||||
valid := true
|
valid := true
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if res, ok := resps[key.Type]; !ok {
|
if res, ok := resps[key.Label]; !ok {
|
||||||
valid = false
|
valid = false
|
||||||
} else if !key.Check(res) {
|
} else if !key.Check(res) {
|
||||||
if !PartialValidation || t.HasPartiallySolved(key) == nil {
|
if !PartialValidation || t.HasPartiallySolved(key) == nil {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
type Key struct {
|
type Key struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
IdExercice int64 `json:"idExercice"`
|
IdExercice int64 `json:"idExercice"`
|
||||||
Type string `json:"type"`
|
Label string `json:"type"`
|
||||||
Checksum []byte `json:"value"`
|
Checksum []byte `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func (e Exercice) GetKeys() ([]Key, error) {
|
||||||
var k Key
|
var k Key
|
||||||
k.IdExercice = e.Id
|
k.IdExercice = e.Id
|
||||||
|
|
||||||
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Type, &k.Checksum); err != nil {
|
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Label, &k.Checksum); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
|
@ -58,7 +58,7 @@ func (e Exercice) AddKey(name string, checksum []byte) (Key, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Key) Update() (int64, error) {
|
func (k Key) Update() (int64, error) {
|
||||||
if res, err := DBExec("UPDATE exercice_keys SET id_exercice = ?, type = ?, cksum = ? WHERE id_key = ?", k.IdExercice, k.Type, k.Checksum, k.Id); err != nil {
|
if res, err := DBExec("UPDATE exercice_keys SET id_exercice = ?, type = ?, cksum = ? WHERE id_key = ?", k.IdExercice, k.Label, k.Checksum, k.Id); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
} else if nb, err := res.RowsAffected(); err != nil {
|
} else if nb, err := res.RowsAffected(); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
|
@ -130,9 +130,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
||||||
} else {
|
} else {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
exercice.Keys = append(exercice.Keys, fmt.Sprintf("%x", k.Checksum)+k.Type)
|
exercice.Keys = append(exercice.Keys, fmt.Sprintf("%x", k.Checksum)+k.Label)
|
||||||
} else {
|
} else {
|
||||||
exercice.Keys = append(exercice.Keys, k.Type)
|
exercice.Keys = append(exercice.Keys, k.Label)
|
||||||
if PartialValidation {
|
if PartialValidation {
|
||||||
exercice.SolvedMat = append(exercice.SolvedMat, t.HasPartiallySolved(k) != nil)
|
exercice.SolvedMat = append(exercice.SolvedMat, t.HasPartiallySolved(k) != nil)
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue