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


Golang User.GetUserInfo方法代码示例

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


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

示例1: ProblemById

// Serves the Problem Page
// To-do: Show recently solved users and their language on sidebar
// To-do: Later, add least execution time log on sidebar
func (this *ProblemController) ProblemById() {
	pid := this.Ctx.Input.Param(":id")
	id, err := strconv.Atoi(pid)
	if err != nil {
		// Redirect to 404
		this.Abort("404")
	}
	p := models.Problem{Pid: id}
	p.GetById()
	if strings.Contains(p.Type, "contest") {
		this.Redirect("/", 302)
		return
	}
	log := models.Problemlogs{Pid: id}
	logs, count := log.GetRecentByPid()
	users := make(map[int]models.User)
	if count == 0 {
		this.Data["recentlySolvedUsersExist"] = false
	} else {
		this.Data["recentlySolvedUsersExist"] = true
		for index, element := range logs {
			u := models.User{Uid: element.Uid}
			u.GetUserInfo()
			users[index] = u
		}
	}

	//Author added
	user := models.User{}
	user.Uid = p.Uid
	user.GetUserInfo()
	this.Data["title"] = p.Statement
	this.Data["problem"] = p
	this.Data["Author"] = user.Username
	this.Data["recentlySolvedUsers"] = users

	// Handle problem log of a user
	if this.isLoggedIn() {
		problemLog := models.Problemlogs{}
		problemLog.Pid = p.Pid
		problemLog.Uid = p.Uid
		if problemLog.GetByPidUid() {
			this.Data["userScore"] = problemLog.Points
			this.Data["solvedCount"] = problemLog.Solved
		}
	}

	this.Layout = "layout.tpl"
	this.TplNames = "problem/show.tpl"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHead"] = "problem/submit_head.tpl"
	this.LayoutSections["Sidebar"] = "sidebar/recently_solved_by.tpl"
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:56,代码来源:ProblemController.go

示例2: GetProblem

// /contest/:name/:pid
func (this *ContestController) GetProblem() {
	pid := this.Ctx.Input.Param(":id")
	contestName := this.Ctx.Input.Param(":name")
	id, err := strconv.Atoi(pid)
	if err != nil {
		// Redirect to 404
		this.Abort("404")
	}
	p := models.Problem{Pid: id}
	p.GetById()
	check := strings.Contains(p.Type, contestName)
	if !check {
		this.Redirect("/contest/"+contestName, 302)
		return
	}
	log := models.Problemlogs{Pid: id}
	logs, count := log.GetRecentByPid()
	users := make(map[int]models.User)
	if count == 0 {
		this.Data["recentlySolvedUsersExist"] = false
	} else {
		this.Data["recentlySolvedUsersExist"] = true
		for index, element := range logs {
			u := models.User{Uid: element.Uid}
			u.GetUserInfo()
			users[index] = u
		}
	}

	this.Data["title"] = p.Statement
	this.Data["problem"] = p
	this.Data["Author"] = contestName
	this.Data["recentlySolvedUsers"] = users

	// Handle problem log of a user
	if this.isLoggedIn() {
		problemLog := models.Problemlogs{}
		problemLog.Pid = p.Pid
		problemLog.Uid = p.Uid
		if problemLog.GetByPidUid() {
			this.Data["userScore"] = problemLog.Points
			this.Data["solvedCount"] = problemLog.Solved
		}
	}
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:46,代码来源:ContestController.go

示例3: Login

func (this *UserController) Login() {
	uid := this.GetSession("Uid")
	if uid != nil {
		this.Redirect("/", 302)
	}

	if this.Ctx.Input.Param("0") == "submit" {
		user := models.User{
			Username: this.GetString("username"),
			Password: this.GetString("password"),
		}
		// Handle the flash messages
		err := user.LoginVerify()
		if err != nil {
			flash := beego.NewFlash()
			flash.Error(err.Error())
			flash.Store(&this.Controller)
		}
		if user.Login() == true {
			this.SetSession("Uid", this.GetString("username"))
			user.GetUserInfo()
			this.SetSession("id", user.Uid)

			// store the user ID in the session
			this.Redirect("/", 302)
		}
		//If login failed, flash a relevent message
	}

	this.Data["title"] = "Login"

	this.Layout = "layout.tpl"
	this.TplNames = "user/login.tpl"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHead"] = ""
	this.LayoutSections["Sidebar"] = ""
	this.LayoutSections["ErrorHead"] = "errorHead.tpl"
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:38,代码来源:UserController.go


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