update user
This commit is contained in:
@@ -72,19 +72,20 @@ func UsersItemPatch(w http.ResponseWriter, r *http.Request) {
|
||||
form := utils.BodyRead(r)
|
||||
user := models.User{ID: utils.ParamInt(mux.Vars(r)["id"], 0)}
|
||||
configs.ORMDB().First(&user)
|
||||
if name, ok := form["name"]; ok {
|
||||
user.Name = name.(string)
|
||||
if name, ok := form["name"].(string); ok {
|
||||
user.Name = name
|
||||
}
|
||||
if email, ok := form["email"]; ok {
|
||||
user.Email = email.(string)
|
||||
if email, ok := form["email"].(string); ok {
|
||||
user.Email = email
|
||||
}
|
||||
if password, ok := form["password"]; ok {
|
||||
if password, ok := form["password"].(string); ok {
|
||||
user.Slat = uuid.New().String()
|
||||
user.Password = fmt.Sprintf("%x", md5.Sum([]byte(password.(string)+user.Slat)))
|
||||
user.Password = fmt.Sprintf("%x", md5.Sum([]byte(password+user.Slat)))
|
||||
}
|
||||
if admin, ok := form["admin"]; ok {
|
||||
user.Admin = admin.(bool)
|
||||
if admin, ok := form["admin"].(bool); ok {
|
||||
user.Admin = admin
|
||||
}
|
||||
|
||||
configs.ORMDB().Save(&user)
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Write(utils.ToJSON(user))
|
||||
|
Reference in New Issue
Block a user