本文整理汇总了Golang中GoOnlineJudge/model.UserModel.Update方法的典型用法代码示例。如果您正苦于以下问题:Golang UserModel.Update方法的具体用法?Golang UserModel.Update怎么用?Golang UserModel.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GoOnlineJudge/model.UserModel
的用法示例。
在下文中一共展示了UserModel.Update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Update
//@URL: /profile @method: POST
func (uc *UserController) Update() {
restweb.Logger.Debug("User Update")
var one model.User
one.Nick = uc.Input.Get("user[nick]")
one.Mail = uc.Input.Get("user[mail]")
one.School = uc.Input.Get("user[school]")
one.Motto = uc.Input.Get("user[motto]")
one.ShareCode, _ = strconv.ParseBool(uc.Input.Get("user[share_code]"))
restweb.Logger.Debug(uc.Input.Get("user[share_code]"))
restweb.Logger.Debug(one.ShareCode)
if one.Nick == "" {
hint := make(map[string]string)
hint["nick"] = "Nick should not be empty."
uc.W.WriteHeader(400)
b, _ := json.Marshal(&hint)
uc.W.Write(b)
} else {
userModel := model.UserModel{}
err := userModel.Update(uc.Uid, one)
if err != nil {
http.Error(uc.W, err.Error(), 500)
return
}
uc.W.WriteHeader(200)
}
}
示例2: Update
func (this *UserController) Update(w http.ResponseWriter, r *http.Request) {
class.Logger.Debug("User Update")
this.Init(w, r)
ok := 1
hint := make(map[string]string)
hint["uid"] = this.Uid
var one model.User
one.Nick = r.FormValue("user[nick]")
one.Mail = r.FormValue("user[mail]")
one.School = r.FormValue("user[school]")
one.Motto = r.FormValue("user[motto]")
if one.Nick == "" {
ok, hint["nick"] = 0, "Nick should not be empty."
}
if ok == 1 {
userModel := model.UserModel{}
err := userModel.Update(this.Uid, one)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
w.WriteHeader(200)
} else {
w.WriteHeader(400)
}
b, err := json.Marshal(&hint)
if err != nil {
http.Error(w, "json error", 400)
return
}
w.Write(b)
}