Requires login to see themes (when using fic-nginx container)
This commit is contained in:
parent
51e3bfde90
commit
cb2cd7f4c0
5 changed files with 53 additions and 8 deletions
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -298,12 +299,43 @@ func genTeamsFile() error {
|
|||
|
||||
// Generate general themes.json file
|
||||
func genThemesFile() error {
|
||||
if themes, err := fic.ExportThemes(); err != nil {
|
||||
return err
|
||||
} else if j, err := json.Marshal(themes); err != nil {
|
||||
return err
|
||||
} else if err = ioutil.WriteFile(path.Join(TeamsDir, "themes.json"), j, 0666); err != nil {
|
||||
return err
|
||||
themes, err := fic.ExportThemes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to generate themes: %w", err)
|
||||
}
|
||||
|
||||
var wr io.Writer
|
||||
|
||||
themesfd, err := os.Create(path.Join(TeamsDir, "themes.json"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to re-create themes.json: %w", err)
|
||||
}
|
||||
defer themesfd.Close()
|
||||
|
||||
themeswait, err := os.Create(path.Join(TeamsDir, "themes-wait.json"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to re-create themes-wait.json: %w", err)
|
||||
}
|
||||
defer themeswait.Close()
|
||||
|
||||
if allowRegistration {
|
||||
wr = io.MultiWriter(themesfd, themeswait)
|
||||
} else {
|
||||
wr = themesfd
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(wr)
|
||||
err = enc.Encode(themes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to encode themes.json: %w", err)
|
||||
}
|
||||
|
||||
if !allowRegistration {
|
||||
enc = json.NewEncoder(themeswait)
|
||||
err = enc.Encode(map[string]string{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to encode themes-wait.json: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -23,13 +23,16 @@ var TeamsDir string
|
|||
var ChStarted = false
|
||||
var lastRegeneration time.Time
|
||||
var skipInitialGeneration = false
|
||||
var allowRegistration bool
|
||||
|
||||
func reloadSettings(config *settings.Settings) {
|
||||
fic.HintCoefficient = config.HintCurCoefficient
|
||||
fic.WChoiceCoefficient = config.WChoiceCurCoefficient
|
||||
fic.ExerciceCurrentCoefficient = config.ExerciceCurCoefficient
|
||||
ChStarted = config.Start.Unix() > 0 && time.Since(config.Start) >= 0
|
||||
if fic.PartialValidation != config.PartialValidation || fic.UnlockedChallengeDepth != config.UnlockedChallengeDepth || fic.UnlockedChallengeUpTo != config.UnlockedChallengeUpTo || fic.DisplayAllFlags != config.DisplayAllFlags || fic.FirstBlood != config.FirstBlood || fic.SubmissionCostBase != config.SubmissionCostBase || fic.SubmissionUniqueness != config.SubmissionUniqueness || fic.DiscountedFactor != config.DiscountedFactor {
|
||||
if allowRegistration != config.AllowRegistration || fic.PartialValidation != config.PartialValidation || fic.UnlockedChallengeDepth != config.UnlockedChallengeDepth || fic.UnlockedChallengeUpTo != config.UnlockedChallengeUpTo || fic.DisplayAllFlags != config.DisplayAllFlags || fic.FirstBlood != config.FirstBlood || fic.SubmissionCostBase != config.SubmissionCostBase || fic.SubmissionUniqueness != config.SubmissionUniqueness || fic.DiscountedFactor != config.DiscountedFactor {
|
||||
allowRegistration = config.AllowRegistration
|
||||
|
||||
fic.PartialValidation = config.PartialValidation
|
||||
fic.UnlockedChallengeDepth = config.UnlockedChallengeDepth
|
||||
fic.UnlockedChallengeUpTo = config.UnlockedChallengeUpTo
|
||||
|
|
|
|||
Reference in a new issue