diff --git a/users.go b/users.go index a5982f3a..eaf2fbf4 100644 --- a/users.go +++ b/users.go @@ -263,8 +263,15 @@ func usersPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) u.Commands = []string{} } - ouser, ok := c.FM.Users[u.Username] - if !ok { + var ouser *User + for _, user := range c.FM.Users { + if user.ID == id { + ouser = user + break + } + } + + if ouser == nil { return http.StatusNotFound, nil } @@ -292,6 +299,12 @@ func usersPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) 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 return http.StatusOK, nil }