settings: add canJoinTeam parameter

This commit is contained in:
nemunaire 2019-02-04 18:14:46 +01:00
parent 921644deb4
commit 2b95995104
7 changed files with 159 additions and 36 deletions

View File

@ -170,6 +170,7 @@ func main() {
FirstBlood: fic.FirstBlood,
SubmissionCostBase: fic.SubmissionCostBase,
AllowRegistration: false,
CanJoinTeam: false,
DenyNameChange: false,
EnableResolutionRoute: false,
PartialValidation: true,

View File

@ -114,6 +114,13 @@
</label>
</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">
<label class="custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" ng-model="config.denyNameChange">

View File

@ -48,6 +48,8 @@ var lastRegeneration time.Time
var skipInitialGeneration = false
func reloadSettings(config settings.FICSettings) {
allowRegistration = config.AllowRegistration
canJoinTeam = config.CanJoinTeam
fic.HintCoefficient = config.HintCurCoefficient
fic.WChoiceCoefficient = config.WChoiceCurCoefficient
fic.ExerciceCurrentCoefficient = config.ExerciceCurCoefficient

View File

@ -12,29 +12,74 @@ import (
"srs.epita.fr/fic-server/libfic"
)
var (
allowRegistration = false
canJoinTeam = false
)
type uTeamRegistration struct {
TeamName string
JTeam int64
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) {
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)
} else if err := json.Unmarshal(cnt_raw, &nTeam); err != nil {
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) {
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)
} else {
for _, m := range nTeam.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)
}
}
registrationProcess(team, nTeam.Members, team_id)
if err := os.Remove(pathname); err != nil {
log.Println("[WRN]", err)
@ -43,26 +88,10 @@ func treatRegistration(pathname string, team_id string) {
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() {
if err := genTeamMyFile(team); err != nil {
log.Println("Team generation error: ", err)
}
if err := genEventsFile(); err != nil {
log.Println("events.json generation error: ", err)
}
if err := genTeamsFile(); err != nil {
log.Println("teams.json generation error: ", err)
}
}()
}
}

View File

@ -712,7 +712,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.title = "Bienvenue au challenge forensic !";
$rootScope.authors = null;
$scope.form = {"teamName": "", "members": [{}]};
$scope.form = {"teamName": "", "jTeam": 0, "members": [{}]};
$scope.AddMember = function() {
$scope.form.members.push({});
@ -725,16 +725,29 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$('#teamName').addClass("is-invalid")
return;
} else {
$('#teamName').removeClass("is-invalid")
$('#vldBtn').removeClass("input-group-btn");
$('#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() {
if (!$scope.part2)
return $scope.Validate();
var commonsubmit = function(registration) {
// Remove empty members
$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 != ""));
@ -748,6 +761,8 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
return;
}
$scope.form.jTeam = parseInt($scope.form.jTeam);
$http({
url: "registration",
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){
if (my)
$location.url(".");

View File

@ -26,8 +26,8 @@
<div class="col-sm-10">
<div class="input-group">
<input type="text" class="form-control" id="teamName" ng-model="form.teamName" placeholder="" autofocus required>
<span class="input-group-btn" id="vldBtn">
<button class="btn btn-info" type="button" ng-click="Validate()">Valider</button>
<span class="input-group-append" id="vldBtn">
<button class="btn btn-info" type="button" ng-click="Validate()" ng-disabled="form.jTeam">Valider</button>
</span>
<div class="invalid-feedback">
Veuillez indiquer un nom d'équipe valide.
@ -36,13 +36,16 @@
</div>
</div>
<div ng-if="part2">
<h4 style="text-indent: 0; margin-top: 20px">
<div ng-if="partR">
<h4 style="text-indent: 0; margin-top: 20px" ng-if="!settings.canJoinTeam">
Membres d'équipe
<button class="btn btn-sm btn-success" type="button" ng-click="AddMember()">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un membre
</button>
</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>
<div class="row form-group" ng-repeat="(mid, member) in form.members">
<div class="col-sm">
@ -57,13 +60,13 @@
<div class="col-sm">
<input type="text" class="form-control" ng-model="member.company" placeholder="Entreprise">
</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)">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</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>
S'inscrire
</button>
@ -71,3 +74,53 @@
</form>
</div>
<div class="jumbotron niceborder" style="text-indent: 1em" ng-if="settings.canJoinTeam">
<p>
Si votre équipe est déjà créée, rejoignez-là&nbsp;!
</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>

View File

@ -51,6 +51,8 @@ type FICSettings struct {
// AllowRegistration permits unregistered Team to register themselves.
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 bool `json:"denyNameChange"`
// EnableResolutionRoute activates the route displaying resolution movies.