From 23dbcf33aee00eea02e0313abb93fea77167120f Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 3 Aug 2020 00:12:45 +0100 Subject: [PATCH] reinitialize validator on settings change --- api.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api.go b/api.go index 6f6b2f9a..20fdcd7e 100644 --- a/api.go +++ b/api.go @@ -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 {