This commit is contained in:
Henrique Dias 2017-07-19 07:55:58 +01:00
parent 03755f6846
commit 40b31bd291
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730

View File

@ -263,8 +263,15 @@ func usersPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
u.Commands = []string{} u.Commands = []string{}
} }
ouser, ok := c.FM.Users[u.Username] var ouser *User
if !ok { for _, user := range c.FM.Users {
if user.ID == id {
ouser = user
break
}
}
if ouser == nil {
return http.StatusNotFound, nil return http.StatusNotFound, nil
} }
@ -292,6 +299,12 @@ func usersPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request)
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }
// If the user changed the username, delete the old user
// from the in-memory user map.
if ouser.Username != u.Username {
delete(c.FM.Users, ouser.Username)
}
c.FM.Users[u.Username] = &u c.FM.Users[u.Username] = &u
return http.StatusOK, nil return http.StatusOK, nil
} }