当前位置: 首页>>代码示例>>Golang>>正文


Golang UserModel.Insert方法代码示例

本文整理汇总了Golang中GoOnlineJudge/model.UserModel.Insert方法的典型用法代码示例。如果您正苦于以下问题:Golang UserModel.Insert方法的具体用法?Golang UserModel.Insert怎么用?Golang UserModel.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GoOnlineJudge/model.UserModel的用法示例。


在下文中一共展示了UserModel.Insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Register

//@URL: /users @method:POST
func (uc *UserController) Register() {
	restweb.Logger.Debug("User Register")

	var one model.User
	userModel := model.UserModel{}

	uid := uc.Input.Get("user[handle]")
	nick := uc.Input.Get("user[nick]")
	pwd := uc.Input.Get("user[password]")
	pwdConfirm := uc.Input.Get("user[confirmPassword]")
	one.Mail = uc.Input.Get("user[mail]")
	one.School = uc.Input.Get("user[school]")
	one.Motto = uc.Input.Get("user[motto]")

	valid := restweb.Validation{}
	valid.MinSize(uid, 4, "uid")
	valid.Match(uid, "\\w+", "uid")

	if !valid.HasError {
		_, err := userModel.Detail(uid)
		if err != nil && err != model.NotFoundErr {
			http.Error(uc.W, err.Error(), 500)
			return
		} else if err == nil {
			valid.AppendError("uid", "Handle is currently in use.")
		}
	}

	valid.Required(nick, "nick")
	valid.MinSize(pwd, 6, "pwd")
	valid.Equal(pwd, pwdConfirm, "pwdConfirm")
	valid.Mail(one.Mail, "mail")

	if !valid.HasError {
		one.Uid = uid
		one.Nick = nick
		one.Pwd = pwd
		one.Privilege = config.PrivilegePU

		err := userModel.Insert(one)
		if err != nil {
			uc.Error(err.Error(), 500)
			return
		}

		uc.W.Header().Add("Location", "/users/"+uid)
		uc.W.WriteHeader(201)
	} else {
		hint := valid.RenderErrMap()
		b, _ := json.Marshal(&hint)
		uc.W.WriteHeader(400)
		uc.W.Write(b)
	}
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:55,代码来源:user.go

示例2: Register

func (this *UserController) Register(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Register")
	this.Init(w, r)

	var one model.User
	userModel := model.UserModel{}

	uid := r.FormValue("user[handle]")
	nick := r.FormValue("user[nick]")
	pwd := r.FormValue("user[password]")
	pwdConfirm := r.FormValue("user[confirmPassword]")
	one.Mail = r.FormValue("user[mail]")
	one.School = r.FormValue("user[school]")
	one.Motto = r.FormValue("user[motto]")

	ok := 1
	hint := make(map[string]string)

	if uid == "" {
		ok, hint["uid"] = 0, "Handle should not be empty."
	} else {
		qry := make(map[string]string)
		qry["uid"] = uid
		ret, err := userModel.List(qry)
		if err != nil {
			http.Error(w, err.Error(), 500)
		} else if len(ret) > 0 {
			ok, hint["uid"] = 0, "This handle is currently in use."
		}
	}
	if nick == "" {
		ok, hint["nick"] = 0, "Nick should not be empty."
	}
	if len(pwd) < 6 {
		ok, hint["pwd"] = 0, "Password should contain at least six characters."
	}
	if pwd != pwdConfirm {
		ok, hint["pwdConfirm"] = 0, "Confirmation mismatched."
	}
	if ok == 1 {
		one.Uid = uid
		one.Nick = nick
		one.Pwd = pwd
		//one.Privilege = config.PrivilegePU
		one.Privilege = config.PrivilegeAD

		err := userModel.Insert(one)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}

		this.SetSession(w, r, "Uid", uid)
		this.SetSession(w, r, "Privilege", "1")
		w.WriteHeader(200)
	} else {
		b, err := json.Marshal(&hint)
		if err != nil {
			http.Error(w, "json error", 500)
			return
		}

		w.WriteHeader(400)
		w.Write(b)
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:66,代码来源:user.go


注:本文中的GoOnlineJudge/model.UserModel.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。