Fix for #142
parent
03755f6846
commit
40b31bd291
17
users.go
17
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue