func (this *UserWebAPIV1Controller) PutPassword() { user := new(models.User) var p map[string]interface{} if err := json.Unmarshal(this.Ctx.Input.CopyBody(), &p); err != nil { this.JSONOut(http.StatusBadRequest, err.Error(), nil) return } if exist, _, err := user.Has(this.Ctx.Input.Param(":username")); err != nil { this.JSONOut(http.StatusBadRequest, err.Error(), nil) return } else if exist == false && err == nil { this.JSONOut(http.StatusBadRequest, "Search user error", nil) return } else if p["oldPassword"].(string) != user.Password { this.JSONOut(http.StatusBadRequest, "account and password not match", nil) return } user.Password = p["newPassword"].(string) user.Updated = time.Now().UnixNano() / int64(time.Millisecond) if err := user.Save(); err != nil { this.JSONOut(http.StatusBadRequest, err.Error(), nil) return } memo, _ := json.Marshal(this.Ctx.Input.Header) user.Log(models.ACTION_UPDATE_PASSWORD, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, user.Id, memo) this.JSONOut(http.StatusOK, "Update password success!", nil) return }
func (this *UserWebAPIV1Controller) GetUser() { user := new(models.User) if exist, _, err := user.Has(this.Ctx.Input.Param(":username")); err != nil { this.JSONOut(http.StatusBadRequest, err.Error(), nil) return } else if exist == false && err == nil { this.JSONOut(http.StatusBadRequest, "Search user error", nil) return } user.Password = "******" this.JSONOut(http.StatusOK, "", user) return }