settings: add canJoinTeam parameter
This commit is contained in:
parent
921644deb4
commit
2b95995104
7 changed files with 159 additions and 36 deletions
|
@ -170,6 +170,7 @@ func main() {
|
||||||
FirstBlood: fic.FirstBlood,
|
FirstBlood: fic.FirstBlood,
|
||||||
SubmissionCostBase: fic.SubmissionCostBase,
|
SubmissionCostBase: fic.SubmissionCostBase,
|
||||||
AllowRegistration: false,
|
AllowRegistration: false,
|
||||||
|
CanJoinTeam: false,
|
||||||
DenyNameChange: false,
|
DenyNameChange: false,
|
||||||
EnableResolutionRoute: false,
|
EnableResolutionRoute: false,
|
||||||
PartialValidation: true,
|
PartialValidation: true,
|
||||||
|
|
|
@ -114,6 +114,13 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-check">
|
||||||
|
<label class="custom-control custom-checkbox">
|
||||||
|
<input class="custom-control-input" type="checkbox" ng-model="config.canJoinTeam" ng-disabled="!config.allowRegistration">
|
||||||
|
<span class="custom-control-label">Les participants sans équipe peuvent en rejoindre une</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<label class="custom-control custom-checkbox">
|
<label class="custom-control custom-checkbox">
|
||||||
<input class="custom-control-input" type="checkbox" ng-model="config.denyNameChange">
|
<input class="custom-control-input" type="checkbox" ng-model="config.denyNameChange">
|
||||||
|
|
|
@ -48,6 +48,8 @@ var lastRegeneration time.Time
|
||||||
var skipInitialGeneration = false
|
var skipInitialGeneration = false
|
||||||
|
|
||||||
func reloadSettings(config settings.FICSettings) {
|
func reloadSettings(config settings.FICSettings) {
|
||||||
|
allowRegistration = config.AllowRegistration
|
||||||
|
canJoinTeam = config.CanJoinTeam
|
||||||
fic.HintCoefficient = config.HintCurCoefficient
|
fic.HintCoefficient = config.HintCurCoefficient
|
||||||
fic.WChoiceCoefficient = config.WChoiceCurCoefficient
|
fic.WChoiceCoefficient = config.WChoiceCurCoefficient
|
||||||
fic.ExerciceCurrentCoefficient = config.ExerciceCurCoefficient
|
fic.ExerciceCurrentCoefficient = config.ExerciceCurCoefficient
|
||||||
|
|
|
@ -12,29 +12,74 @@ import (
|
||||||
"srs.epita.fr/fic-server/libfic"
|
"srs.epita.fr/fic-server/libfic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
allowRegistration = false
|
||||||
|
canJoinTeam = false
|
||||||
|
)
|
||||||
|
|
||||||
type uTeamRegistration struct {
|
type uTeamRegistration struct {
|
||||||
TeamName string
|
TeamName string
|
||||||
|
JTeam int64
|
||||||
Members []fic.Member
|
Members []fic.Member
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registrationProcess(team fic.Team, members []fic.Member, team_id string) {
|
||||||
|
for _, m := range members {
|
||||||
|
// Force Id to 0, as it shouldn't have been defined yet
|
||||||
|
m.Id = 0
|
||||||
|
if err := team.GainMember(m); err != nil {
|
||||||
|
log.Println("[WRN] Unable to add member (", m, ") to team (", team, "):", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
teamDirPath := fmt.Sprintf("%d", team.Id)
|
||||||
|
|
||||||
|
// Create team directories into TEAMS
|
||||||
|
if err := os.MkdirAll(path.Join(TeamsDir, teamDirPath), 0777); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
}
|
||||||
|
if err := os.Symlink(teamDirPath, path.Join(TeamsDir, team_id)); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := genTeamMyFile(team); err != nil {
|
||||||
|
log.Println("Team generation error: ", err)
|
||||||
|
}
|
||||||
|
if err := genTeamsFile(); err != nil {
|
||||||
|
log.Println("teams.json generation error: ", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func treatRegistration(pathname string, team_id string) {
|
func treatRegistration(pathname string, team_id string) {
|
||||||
var nTeam uTeamRegistration
|
var nTeam uTeamRegistration
|
||||||
|
|
||||||
if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
if !allowRegistration {
|
||||||
|
log.Println("[ERR] Registration received, whereas disabled. Skipped.")
|
||||||
|
} else if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
||||||
log.Println("[ERR]", err)
|
log.Println("[ERR]", err)
|
||||||
} else if err := json.Unmarshal(cnt_raw, &nTeam); err != nil {
|
} else if err := json.Unmarshal(cnt_raw, &nTeam); err != nil {
|
||||||
log.Println("[ERR]", err)
|
log.Println("[ERR]", err)
|
||||||
|
} else if nTeam.JTeam > 0 {
|
||||||
|
if !canJoinTeam {
|
||||||
|
log.Println("[ERR] Join team received, whereas disabled. Skipped.")
|
||||||
|
} else if len(nTeam.Members) != 1 {
|
||||||
|
log.Printf("[ERR] Join team received, with incorrect member length: %d. Skipped.\n", len(nTeam.Members))
|
||||||
|
} else if team, err := fic.GetTeam(nTeam.JTeam); err != nil {
|
||||||
|
log.Printf("[ERR] Unable to join registered team %s: %s\n", nTeam.JTeam, err)
|
||||||
|
} else {
|
||||||
|
registrationProcess(team, nTeam.Members, team_id)
|
||||||
|
|
||||||
|
if err := os.Remove(pathname); err != nil {
|
||||||
|
log.Println("[WRN]", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if validTeamName(nTeam.TeamName) {
|
} else if validTeamName(nTeam.TeamName) {
|
||||||
if team, err := fic.CreateTeam(nTeam.TeamName, uint32(rand.Int31n(16581376))); err != nil {
|
if team, err := fic.CreateTeam(nTeam.TeamName, uint32(rand.Int31n(16581376))); err != nil {
|
||||||
log.Printf("[ERR] Unable to register new team %s: %s\n", nTeam.TeamName, err)
|
log.Printf("[ERR] Unable to register new team %s: %s\n", nTeam.TeamName, err)
|
||||||
} else {
|
} else {
|
||||||
for _, m := range nTeam.Members {
|
registrationProcess(team, nTeam.Members, team_id)
|
||||||
// Force Id to 0, as it shouldn't have been defined yet
|
|
||||||
m.Id = 0
|
|
||||||
if err := team.GainMember(m); err != nil {
|
|
||||||
log.Println("[WRN] Unable to add member (", m, ") to team (", team, "): ", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.Remove(pathname); err != nil {
|
if err := os.Remove(pathname); err != nil {
|
||||||
log.Println("[WRN]", err)
|
log.Println("[WRN]", err)
|
||||||
|
@ -43,26 +88,10 @@ func treatRegistration(pathname string, team_id string) {
|
||||||
log.Println("[WRN] Unable to create event:", err)
|
log.Println("[WRN] Unable to create event:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
teamDirPath := fmt.Sprintf("%d", team.Id)
|
|
||||||
|
|
||||||
// Create team directories into TEAMS
|
|
||||||
if err := os.MkdirAll(path.Join(TeamsDir, teamDirPath), 0777); err != nil {
|
|
||||||
log.Println("[ERR]", err)
|
|
||||||
}
|
|
||||||
if err := os.Symlink(teamDirPath, path.Join(TeamsDir, team_id)); err != nil {
|
|
||||||
log.Println("[ERR]", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := genTeamMyFile(team); err != nil {
|
|
||||||
log.Println("Team generation error: ", err)
|
|
||||||
}
|
|
||||||
if err := genEventsFile(); err != nil {
|
if err := genEventsFile(); err != nil {
|
||||||
log.Println("events.json generation error: ", err)
|
log.Println("events.json generation error: ", err)
|
||||||
}
|
}
|
||||||
if err := genTeamsFile(); err != nil {
|
|
||||||
log.Println("teams.json generation error: ", err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -712,7 +712,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
$rootScope.title = "Bienvenue au challenge forensic !";
|
$rootScope.title = "Bienvenue au challenge forensic !";
|
||||||
$rootScope.authors = null;
|
$rootScope.authors = null;
|
||||||
|
|
||||||
$scope.form = {"teamName": "", "members": [{}]};
|
$scope.form = {"teamName": "", "jTeam": 0, "members": [{}]};
|
||||||
|
|
||||||
$scope.AddMember = function() {
|
$scope.AddMember = function() {
|
||||||
$scope.form.members.push({});
|
$scope.form.members.push({});
|
||||||
|
@ -725,16 +725,29 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
$('#teamName').addClass("is-invalid")
|
$('#teamName').addClass("is-invalid")
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
$('#teamName').removeClass("is-invalid")
|
||||||
$('#vldBtn').removeClass("input-group-btn");
|
$('#vldBtn').removeClass("input-group-btn");
|
||||||
$('#vldBtn').css("display", "none");
|
$('#vldBtn').css("display", "none");
|
||||||
$scope.part2 = true;
|
$('#jvldBtn').css("display", "none");
|
||||||
|
$scope.partR = true;
|
||||||
|
$scope.partJ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$scope.JValidate = function() {
|
||||||
|
if (!$scope.teams[$scope.form.jTeam]) {
|
||||||
|
$('#jTeam').addClass("is-invalid")
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$('#jTeam').removeClass("is-invalid")
|
||||||
|
$('#jvldBtn').removeClass("input-group-btn");
|
||||||
|
$('#jvldBtn').css("display", "none");
|
||||||
|
$('#vldBtn').css("display", "none");
|
||||||
|
$scope.partR = false;
|
||||||
|
$scope.partJ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.rsubmit = function() {
|
var commonsubmit = function(registration) {
|
||||||
if (!$scope.part2)
|
|
||||||
return $scope.Validate();
|
|
||||||
|
|
||||||
// Remove empty members
|
// Remove empty members
|
||||||
$scope.form.members = $scope.form.members.filter(function(m) {
|
$scope.form.members = $scope.form.members.filter(function(m) {
|
||||||
return ((m.lastname != undefined && m.lastname != "") || (m.firstname != undefined && m.firstname != "") || (m.nickname != undefined && m.nickname != ""));
|
return ((m.lastname != undefined && m.lastname != "") || (m.firstname != undefined && m.firstname != "") || (m.nickname != undefined && m.nickname != ""));
|
||||||
|
@ -748,6 +761,8 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.form.jTeam = parseInt($scope.form.jTeam);
|
||||||
|
|
||||||
$http({
|
$http({
|
||||||
url: "registration",
|
url: "registration",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -771,6 +786,20 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.rsubmit = function() {
|
||||||
|
if (!$scope.partR)
|
||||||
|
return $scope.Validate();
|
||||||
|
else
|
||||||
|
return commonsubmit(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.jsubmit = function() {
|
||||||
|
if (!$scope.partJ)
|
||||||
|
return $scope.JValidate();
|
||||||
|
else
|
||||||
|
return commonsubmit(false);
|
||||||
|
}
|
||||||
|
|
||||||
$scope.$watch("my", function(my){
|
$scope.$watch("my", function(my){
|
||||||
if (my)
|
if (my)
|
||||||
$location.url(".");
|
$location.url(".");
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" class="form-control" id="teamName" ng-model="form.teamName" placeholder="" autofocus required>
|
<input type="text" class="form-control" id="teamName" ng-model="form.teamName" placeholder="" autofocus required>
|
||||||
<span class="input-group-btn" id="vldBtn">
|
<span class="input-group-append" id="vldBtn">
|
||||||
<button class="btn btn-info" type="button" ng-click="Validate()">Valider</button>
|
<button class="btn btn-info" type="button" ng-click="Validate()" ng-disabled="form.jTeam">Valider</button>
|
||||||
</span>
|
</span>
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
Veuillez indiquer un nom d'équipe valide.
|
Veuillez indiquer un nom d'équipe valide.
|
||||||
|
@ -36,13 +36,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-if="part2">
|
<div ng-if="partR">
|
||||||
<h4 style="text-indent: 0; margin-top: 20px">
|
<h4 style="text-indent: 0; margin-top: 20px" ng-if="!settings.canJoinTeam">
|
||||||
Membres d'équipe
|
Membres d'équipe
|
||||||
<button class="btn btn-sm btn-success" type="button" ng-click="AddMember()">
|
<button class="btn btn-sm btn-success" type="button" ng-click="AddMember()">
|
||||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un membre
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un membre
|
||||||
</button>
|
</button>
|
||||||
</h4>
|
</h4>
|
||||||
|
<h4 style="text-indent: 0; margin-top: 20px" ng-if="settings.canJoinTeam">
|
||||||
|
Chef d'équipe
|
||||||
|
</h4>
|
||||||
<p ng-if="message" ng-class="messageClass" ng-bind="message"></p>
|
<p ng-if="message" ng-class="messageClass" ng-bind="message"></p>
|
||||||
<div class="row form-group" ng-repeat="(mid, member) in form.members">
|
<div class="row form-group" ng-repeat="(mid, member) in form.members">
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
|
@ -57,13 +60,13 @@
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<input type="text" class="form-control" ng-model="member.company" placeholder="Entreprise">
|
<input type="text" class="form-control" ng-model="member.company" placeholder="Entreprise">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-auto">
|
<div class="col-sm-auto" ng-if="!settings.canJoinTeam">
|
||||||
<button class="btn btn-danger" type="button" ng-click="RemoveMember(mid)">
|
<button class="btn btn-danger" type="button" ng-click="RemoveMember(mid)">
|
||||||
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-info" style="margin-left: 40%;" type="submit">
|
<button class="btn btn-info" style="margin-left: 40%;" type="submit" ng-disabled="form.jTeam">
|
||||||
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
|
||||||
S'inscrire
|
S'inscrire
|
||||||
</button>
|
</button>
|
||||||
|
@ -71,3 +74,53 @@
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="jumbotron niceborder" style="text-indent: 1em" ng-if="settings.canJoinTeam">
|
||||||
|
<p>
|
||||||
|
Si votre équipe est déjà créée, rejoignez-là !
|
||||||
|
</p>
|
||||||
|
<form ng-submit="jsubmit()">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<label for="jTeam" class="col col-form-label">Nom d'équipe</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<div class="input-group">
|
||||||
|
<select class="custom-select" id="jTeam" ng-model="form.jTeam" ng-options="tid as t.name for (tid,t) in teams" required ng-disabled="partJ">
|
||||||
|
</select>
|
||||||
|
<span class="input-group-append" id="jvldBtn">
|
||||||
|
<button class="btn btn-info" type="button" ng-click="JValidate()" ng-disabled="form.teamName">Valider</button>
|
||||||
|
</span>
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
Veuillez sélectionner une équipe valide.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div ng-if="partJ">
|
||||||
|
<h4 style="text-indent: 0; margin-top: 20px">
|
||||||
|
Vos informations
|
||||||
|
</h4>
|
||||||
|
<p ng-if="message" ng-class="messageClass" ng-bind="message"></p>
|
||||||
|
<div class="row form-group" ng-repeat="(mid, member) in form.members">
|
||||||
|
<div class="col-sm">
|
||||||
|
<input type="text" class="form-control" ng-model="member.lastname" placeholder="Nom" autofocus>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm">
|
||||||
|
<input type="text" class="form-control" ng-model="member.firstname" placeholder="Prénom">
|
||||||
|
</div>
|
||||||
|
<div class="col-sm">
|
||||||
|
<input type="text" class="form-control" ng-model="member.nickname" placeholder="Pseudo">
|
||||||
|
</div>
|
||||||
|
<div class="col-sm">
|
||||||
|
<input type="text" class="form-control" ng-model="member.company" placeholder="Entreprise">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-info" style="margin-left: 40%;" type="submit" ng-disabled="form.teamName">
|
||||||
|
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
|
||||||
|
Rejoindre
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
|
@ -51,6 +51,8 @@ type FICSettings struct {
|
||||||
|
|
||||||
// AllowRegistration permits unregistered Team to register themselves.
|
// AllowRegistration permits unregistered Team to register themselves.
|
||||||
AllowRegistration bool `json:"allowRegistration"`
|
AllowRegistration bool `json:"allowRegistration"`
|
||||||
|
// CanJoinTeam permits unregistered account to join an already existing team.
|
||||||
|
CanJoinTeam bool `json:"canJoinTeam"`
|
||||||
// DenyNameChange disallow Team to change their name.
|
// DenyNameChange disallow Team to change their name.
|
||||||
DenyNameChange bool `json:"denyNameChange"`
|
DenyNameChange bool `json:"denyNameChange"`
|
||||||
// EnableResolutionRoute activates the route displaying resolution movies.
|
// EnableResolutionRoute activates the route displaying resolution movies.
|
||||||
|
|
Reference in a new issue