Don't mess up unset properties of new nodes/repos

This commit is contained in:
Jakob Borg 2014-05-24 21:00:47 +02:00
parent 8661afcb4f
commit 217f29de76

View File

@ -184,23 +184,24 @@ func restGetConfig(w http.ResponseWriter) {
} }
func restPostConfig(req *http.Request) { func restPostConfig(req *http.Request) {
var prevPassHash = cfg.GUI.Password var newCfg config.Configuration
err := json.NewDecoder(req.Body).Decode(&cfg) err := json.NewDecoder(req.Body).Decode(&newCfg)
if err != nil { if err != nil {
l.Warnln(err) l.Warnln(err)
} else { } else {
if cfg.GUI.Password == "" { if newCfg.GUI.Password == "" {
// Leave it empty // Leave it empty
} else if cfg.GUI.Password != unchangedPassword { } else if newCfg.GUI.Password == unchangedPassword {
hash, err := bcrypt.GenerateFromPassword([]byte(cfg.GUI.Password), 0) newCfg.GUI.Password = cfg.GUI.Password
} else {
hash, err := bcrypt.GenerateFromPassword([]byte(newCfg.GUI.Password), 0)
if err != nil { if err != nil {
l.Warnln(err) l.Warnln(err)
} else { } else {
cfg.GUI.Password = string(hash) newCfg.GUI.Password = string(hash)
} }
} else {
cfg.GUI.Password = prevPassHash
} }
cfg = newCfg
saveConfig() saveConfig()
configInSync = false configInSync = false
} }