// usersUpdate used to update user proprieties // for now tou can only change password func usersUpdate(w http.ResponseWriter, r *http.Request) { if !authorized(w, r) { return } p := struct { Passwd string `json:"passwd"` }{} // body must not be empty if r.Body == nil { httpWriteErrorJson(w, 422, "empty body", "") return } if err := json.NewDecoder(r.Body).Decode(&p); err != nil { httpWriteErrorJson(w, 500, "unable to get JSON body", err.Error()) return } if err := api.UserChangePassword(httpcontext.Get(r, "params").(httprouter.Params).ByName("user"), p.Passwd); err != nil { httpWriteErrorJson(w, 422, "unable to change user password", err.Error()) return } logInfo(r, "password changed for user "+httpcontext.Get(r, "params").(httprouter.Params).ByName("user")) w.WriteHeader(204) return }
{ Name: "update", Usage: "change proprieties of an user", Description: "tmail user update USER -p NEW_PASSWORD", Flags: []cgCli.Flag{ cgCli.StringFlag{ Name: "password, p", Usage: "update user password", }, }, Action: func(c *cgCli.Context) { if len(c.Args()) != 1 { cliDieBadArgs(c) } if c.String("p") != "" { cliHandleErr(api.UserChangePassword(c.Args()[0], c.String("p"))) cliDieOk() } cliDieBadArgs(c) }, }, { Name: "list", Usage: "Return a list of users", Description: "", Action: func(c *cgCli.Context) { users, err := api.UserGetAll() cliHandleErr(err) if len(users) == 0 { println("There is no users yet.") return