//修改账户信息 func (this *Account) Edit() { //Get方法 if this.methodGet { this.Data["token"] = this.token() id, err := this.getParamsInt64(":id") if err != nil { this.errorHandle(utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams"))) return } u, err := users.Get(id) if err != nil { this.errorHandle(utils.JsonMessage(false, "", err.Error())) return } this.Data["user"] = u this.TplNames = this.getTplFileName("edit") this.Render() return } //Post方法 //签名错误,返回重复提交错误 if this.invalidToken() { this.renderLoseToken() return } //数据模型 u := new(models.Users) models.Extend(u, this.xm) u.Id, _ = this.GetInt("id") u.Loginname = this.GetString("loginname") u.Relname = this.GetString("relname") //数据合法性检验 // valid := validation.Validation // valid.Required(u.Loginname, "loginname") // valid.Required(u.Relname, "relname") if data, inv := this.invalidModel(u, "Loginname", "Relname"); inv { this.renderJson(data) return } //提交DDL var data interface{} _, err := users.Update(u) if err != nil { data = utils.JsonMessage(false, "", err.Error()) } else { data = utils.JsonMessage(true, "", "") } this.renderJson(data) }
//新增账户 func (this *Account) Create() { //Get方法 if this.methodGet { this.Data["token"] = this.token() this.Data["password"] = beego.AppConfig.String("DefaultPassword") this.TplNames = this.getTplFileName("create") this.Render() return } //Post方法 //签名错误,返回重复提交错误 if this.invalidToken() { this.renderLoseToken() return } //数据模型 u := new(models.Users) models.Extend(u, this.xm) u.Loginname = this.GetString("loginname") u.Password = this.GetString("password") u.Relname = this.GetString("relname") r, _ := this.GetInt("role") u.Role = int8(r) //数据合法性检验 if data, inv := this.invalidModel(u); inv { this.renderJson(data) return } //提交DDL var data interface{} _, err := users.Add(u) if err != nil { data = utils.JsonMessage(false, "", err.Error()) } else { data = utils.JsonMessage(true, "", "") } this.renderJson(data) }