reinitialize validator on settings change

This commit is contained in:
Harvey Tindall 2020-08-03 00:12:45 +01:00
parent 25348a9b1a
commit 23dbcf33ae
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
1 changed files with 17 additions and 0 deletions

17
api.go
View File

@ -589,6 +589,23 @@ func (ctx *appContext) ModifyConfig(gc *gin.Context) {
}
}
ctx.loadConfig()
// Reinitialize password validator on config change, as opposed to every applicable request like in python.
if _, ok := req["password_validation"]; ok {
ctx.debug.Println("Reinitializing validator")
validatorConf := ValidatorConf{
"characters": ctx.config.Section("password_validation").Key("min_length").MustInt(0),
"uppercase characters": ctx.config.Section("password_validation").Key("upper").MustInt(0),
"lowercase characters": ctx.config.Section("password_validation").Key("lower").MustInt(0),
"numbers": ctx.config.Section("password_validation").Key("number").MustInt(0),
"special characters": ctx.config.Section("password_validation").Key("special").MustInt(0),
}
if !ctx.config.Section("password_validation").Key("enabled").MustBool(false) {
for key := range validatorConf {
validatorConf[key] = 0
}
}
ctx.validator.init(validatorConf)
}
}
// func Restart() error {