From db22c4af1b09b449597537ce50ce4cd50f8160cb Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 25 Jan 2019 07:26:52 +0100 Subject: [PATCH] frontend: polish public version checks --- frontend/static/js/challenge.js | 38 ++++++++++++++++++++++++++------- frontend/static/views/defi.html | 5 ++++- libfic/team_my.go | 4 ++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/frontend/static/js/challenge.js b/frontend/static/js/challenge.js index bbf92bff..4a24f266 100644 --- a/frontend/static/js/challenge.js +++ b/frontend/static/js/challenge.js @@ -19,12 +19,21 @@ function treatFlagKey(flag) { } if (flag.found == null && flag.soluce !== undefined) { - if (check === undefined) check = true; + if (flag.value && flag.soluce) { + if (flag.ignore_case) + flag.value = flag.value.toLowerCase(); + if (flag.validator_regexp) { + var re = new RegExp(flag.validator_regexp, flag.ignore_case?'ui':'u'); + var match = re.exec(flag.value); + match.shift(); + flag.value = match.join("+"); + } - if (flag.value && flag.soluce == b2sum(flag.value)) - flag.found = new Date(); - check &= flag.found; + if (flag.soluce == b2sum(flag.value)) + flag.found = new Date(); + } } + return flag.found !== undefined && flag.found !== false; } angular.module("FICApp", ["ngRoute", "ngSanitize"]) @@ -329,7 +338,11 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) angular.forEach(data.exercices, function(exercice, eid) { if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].submitted) data.exercices[eid].timeouted = true; + if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].solved !== undefined) + data.exercices[eid].solved = $scope.my.exercices[eid].solved; angular.forEach(exercice.flags, function(flag, fid) { + if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].found !== undefined) + data.exercices[eid].flags[fid].found = $scope.my.exercices[eid].flags[fid].found; if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].value !== undefined) data.exercices[eid].flags[fid].value = $scope.my.exercices[eid].flags[fid].value; if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].values !== undefined) @@ -337,6 +350,10 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) else data.exercices[eid].flags[fid].values = [""]; }); + angular.forEach(exercice.mcqs, function(mcq, mid) { + if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].mcqs && $scope.my.exercices[eid].mcqs[mid] && $scope.my.exercices[eid].mcqs[mid].solved !== undefined) + data.exercices[eid].mcqs[mid].solved = $scope.my.exercices[eid].mcqs[mid].solved; + }); }); angular.forEach(data.exercices, function(exercice, eid) { angular.forEach(exercice.mcqs, function(mcq, mid) { @@ -474,18 +491,23 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) { resp["flags"] = {}; angular.forEach($scope.my.exercices[$rootScope.current_exercice].flags, function(flag,kid) { - treatFlagKey(flag); - if (flag.found == null && flag.soluce === undefined) { - resp["flags"][kid] = flag.value; + if (check === undefined) check = true; + + check &= treatFlagKey(flag) || flag.found; + if (flag.soluce === undefined) { + check = undefined; + if (flag.found == null) { + resp["flags"][kid] = flag.value; + } } }); } if ($scope.my.exercices[$rootScope.current_exercice].mcqs && Object.keys($scope.my.exercices[$rootScope.current_exercice].mcqs).length) { - var soluce = ""; resp["mcqs"] = {}; angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq) { + var soluce = ""; if (mcq.solved == null) { angular.forEach(mcq.choices, function(choice, cid) { if (mcq.soluce !== undefined) { diff --git a/frontend/static/views/defi.html b/frontend/static/views/defi.html index 48c88b7a..64e93bc7 100644 --- a/frontend/static/views/defi.html +++ b/frontend/static/views/defi.html @@ -119,9 +119,12 @@ Défi réussi !
-

+

Vous êtes la {{ my.exercices[current_exercice].solved_rank }} équipe à avoir résolu ce défi à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. Vous avez marqué !

+

+ Bravo, vous avez résolu ce défi à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. Vous marquez ! +



diff --git a/libfic/team_my.go b/libfic/team_my.go index a471652b..0f74415f 100644 --- a/libfic/team_my.go +++ b/libfic/team_my.go @@ -30,6 +30,8 @@ type myTeamFlag struct { Help string `json:"help,omitempty"` Separator string `json:"separator,omitempty"` IgnoreOrder bool `json:"ignore_order,omitempty"` + IgnoreCase bool `json:"ignore_case,omitempty"` + ValidatorRe *string `json:"validator_regexp,omitempty"` Solved *time.Time `json:"found,omitempty"` Soluce string `json:"soluce,omitempty"` Choices map[string]string `json:"choices,omitempty"` @@ -189,6 +191,8 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) { // Retrieve solved state or solution for public iface if t == nil { + flag.IgnoreCase = k.IgnoreCase + flag.ValidatorRe = k.ValidatorRegexp flag.Soluce = hex.EncodeToString(k.Checksum) } else if PartialValidation { flag.Solved = t.HasPartiallySolved(k)