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


Golang UserModel.List方法代码示例

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


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

示例1: List

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

	if this.Privilege != config.PrivilegeAD {
		class.Logger.Info(r.RemoteAddr + " " + this.Uid + " try to visit Admin page")
		this.Data["Title"] = "Warning"
		this.Data["Info"] = "You are not admin!"
		err := this.Execute(w, "view/layout.tpl", "view/400.tpl")
		if err != nil {
			http.Error(w, "tpl error", 500)
			return
		}
		return
	}
	userModel := model.UserModel{}
	userlist, err := userModel.List(nil)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	this.Data["User"] = userlist
	this.Data["Title"] = "Privilege User List"
	this.Data["IsUser"] = true
	this.Data["IsList"] = true

	err = this.Execute(w, "view/admin/layout.tpl", "view/admin/user_list.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:33,代码来源:user.go

示例2: List

//显示具有特殊权限的用户
//@URL: /admin/users/ @method: GET
func (uc *AdminUser) List() {
	restweb.Logger.Debug("Admin Privilege User List")

	if uc.Privilege != config.PrivilegeAD {
		restweb.Logger.Info(uc.Uid + " try to visit Admin page")
		uc.Output["Title"] = "Warning"
		uc.Output["Info"] = "You are not admin!"
		uc.RenderTemplate("view/layout.tpl", "view/400.tpl")
		return
	}

	userModel := model.UserModel{}
	userlist, err := userModel.List(nil)
	if err != nil {
		uc.Error(err.Error(), 500)
		return
	}

	uc.Output["User"] = userlist
	uc.Output["Title"] = "Privilege User List"
	uc.Output["IsUser"] = true
	uc.Output["IsList"] = true
	uc.RenderTemplate("view/admin/layout.tpl", "view/admin/user_list.tpl")
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:26,代码来源:user.go

示例3: Index

//@URL: /ranklist @method: GET
func (rc *RanklistController) Index() {
	restweb.Logger.Debug("Ranklist")

	// Page

	if _, ok := rc.Input["page"]; !ok {
		rc.Input.Set("page", "1")
	}

	userModel := model.UserModel{}
	userList, err := userModel.List(nil)
	if err != nil {
		http.Error(rc.W, err.Error(), 400)
		return
	}

	var count int
	count = 1
	for _, one := range userList {
		if one.Status == config.StatusAvailable {
			count += 1
		}
	}

	var pageCount = (count-1)/config.UserPerPage + 1
	page, err := strconv.Atoi(rc.Input.Get("page"))
	if err != nil {
		rc.Error("args error", 400)
		return
	}
	if page > pageCount {
		rc.Error("args error", 400)
		return
	}

	pageData := rc.GetPage(page, pageCount)
	for k, v := range pageData {
		rc.Output[k] = v
	}

	qry := make(map[string]string)
	qry["offset"] = strconv.Itoa((page - 1) * config.UserPerPage)
	qry["limit"] = strconv.Itoa(config.UserPerPage)
	userList, err = userModel.List(qry)
	if err != nil {

	}

	list := make([]rank, len(userList), len(userList))
	count = 1
	for i, one := range userList {
		list[i].User = *one
		if one.Status == config.StatusAvailable {
			list[count-1].Index = count + (page-1)*config.UserPerPage
			count += 1
		}
	}
	rc.Output["URL"] = "/ranklist?"
	rc.Output["User"] = list
	rc.Output["Title"] = "Ranklist"
	rc.Output["IsRanklist"] = true
	rc.RenderTemplate("view/layout.tpl", "view/ranklist.tpl")
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:64,代码来源:ranklist.go

示例4: 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

示例5: Index

func (this *RanklistController) Index(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Ranklist")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	this.Data["URL"] = "/ranklist"

	// Page
	if _, ok := args["page"]; !ok {
		args["page"] = "1"
	}

	userModel := model.UserModel{}
	userList, err := userModel.List(nil)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	var count int
	count = 1
	for _, one := range userList {
		if one.Status == config.StatusAvailable {
			count += 1
		}
	}

	var pageCount = (count-1)/config.UserPerPage + 1
	page, err := strconv.Atoi(args["page"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}
	if page > pageCount {
		http.Error(w, "args error", 400)
		return
	}

	pageData := this.GetPage(page, pageCount)
	for k, v := range pageData {
		this.Data[k] = v
	}

	qry := make(map[string]string)
	qry["offset"] = strconv.Itoa((page - 1) * config.UserPerPage)
	qry["limit"] = strconv.Itoa(config.UserPerPage)
	userList, err = userModel.List(qry)
	if err != nil {

	}

	list := make([]rank, len(userList), len(userList))
	count = 1
	for i, one := range userList {
		list[i].User = *one
		if one.Status == config.StatusAvailable {
			list[count-1].Index = count
			count += 1
		}
	}
	this.Data["User"] = list
	this.Data["Title"] = "Ranklist"
	this.Data["IsRanklist"] = true
	err = this.Execute(w, "view/layout.tpl", "view/ranklist.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:69,代码来源:ranklist.go


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