Fix for #142
Former-commit-id: e90d48532a52279e1dc201a4a608d7d4feee924f [formerly d2b7a5372ad7bb2b664f205cf0b7b82cd4741cc4] [formerly eec7d5cf1cfc2f7f8351bbac0787de8a53b5e9d8 [formerly 40b31bd291
]]
Former-commit-id: dbfbc3c849a526345848c56be7db48de0eadba5d [formerly 287567052912b6da7bc379bc690a7006d81d0701]
Former-commit-id: 8d42c024c830c2f783cfc75f06b76b355029cca8
pull/726/head
parent
871836f16d
commit
c5b8aee22f
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