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


Golang models.User类代码示例

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


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

示例1: Signup

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

	if this.Ctx.Input.Param("0") != "submit" {
		this.Redirect("/user/login", 302)
	}

	user := models.User{
		Username: this.GetString("username"),
		Password: this.GetString("passkey"),
		Name:     this.GetString("name"),
		College:  this.GetString("college"),
		Email:    this.GetString("email"),
	}
	// All the fields verified, as well checked if username and email are unique
	err := user.SignupVerify()
	if err != nil {
		flash := beego.NewFlash()
		flash.Error(err.Error())
		flash.Store(&this.Controller)
	}
	uid, done := user.Create()

	if done {
		this.SetSession("Uid", this.GetString("username"))
		this.SetSession("id", uid)
		this.Redirect("/", 302)
	}
	this.Redirect("/user/login", 302)
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:33,代码来源:UserController.go

示例2: Show

// To-do: Show programs solved by the user
func (this *UserController) Show() {
	if this.Ctx.Input.Param("0") == "" {
		this.Abort("404")
	}
	user := models.User{Username: this.Ctx.Input.Param("0")}
	if user.GetByUsername() {
		this.Data["title"] = user.Username
		this.Data["userDetails"] = user

		log := models.Problemlogs{Uid: user.Uid}
		logs, count := log.GetByUid()
		problems := make(map[int]models.Problem)
		if count == 0 {
			this.Data["solvedProblemsExist"] = false
		} else {
			this.Data["solvedProblemsExist"] = true
			for index, element := range logs {
				p := models.Problem{Pid: element.Pid}
				p.GetByPid()
				problems[index] = p
			}
		}

		this.Data["solvedProblems"] = problems

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

示例3: saveProblem

// /contest/:name/saveproblem
func (this *ContestController) saveProblem() {
	if !this.isAdmin() {
		return
	}
	contestName := this.Ctx.Input.Param(":name")
	id := this.GetSession("id")
	user := models.User{}
	user.Uid = id.(int)
	points, _ := strconv.Atoi(this.GetString("points"))
	//remove replace foe newlines
	sampleInput := strings.Replace(this.GetString("sample_input"), "\r", "", -1)
	sampleOutput := strings.Replace(this.GetString("sample_output"), "\r", "", -1)
	problem := models.Problem{
		Statement:   this.GetString("statement"),
		Description: this.GetString("description"),
		Constraints: this.GetString("constraints"),
		//Sample_input:  this.GetString("sample_input"),
		//Sample_output: this.GetString("sample_output"),
		Difficulty: this.GetString("difficulty"),
		Points:     points,
		Uid:        id.(int),
	}
	problem.Sample_output = sampleOutput
	problem.Sample_input = sampleInput
	problem.Type = "contest" + contestName
	pid, status := problem.Create()
	if status {
		id := strconv.Itoa(pid)
		this.Redirect("/contest/"+contestName+"/"+id, 302)
	}
	// handle the failure
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:33,代码来源:ContestController.go

示例4: SaveTestCase

func (this *ProblemController) SaveTestCase() {
	if !this.isLoggedIn() {
		this.Redirect("/user/login", 302)
		return
	}

	//Redirect if user doesnt hold editor rights
	uid := this.GetSession("id")
	user := models.User{Uid: uid.(int)}
	if !user.IsEditor() {
		this.Redirect("/", 302)
		return
	}

	pid := this.Ctx.Input.Param(":id")
	id, _ := strconv.Atoi(pid)

	timeout, _ := strconv.Atoi(this.GetString("timeout"))
	//remove string replace
	input := strings.Replace(this.GetString("input"), "\r", "", -1)
	output := strings.Replace(this.GetString("output"), "\r", "", -1)
	testcase := models.Testcases{
		Pid: id,
		//Input:   this.GetString("input"),
		//Output:  this.GetString("output"),
		Timeout: timeout,
	}
	testcase.Input = input
	testcase.Output = output
	done := testcase.Create()
	if done == true {
		this.Redirect("/problem/"+pid, 302)
	}
	this.Redirect("/problem/"+pid+"/addtest", 302)
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:35,代码来源:ProblemController.go

示例5: AddTestCase

func (this *ProblemController) AddTestCase() {
	if !this.isLoggedIn() {
		this.Redirect("/user/login", 302)
		return
	}

	//Redirect if user doesnt hold editor rights
	uid := this.GetSession("id")
	user := models.User{Uid: uid.(int)}
	if !user.IsEditor() {
		this.Redirect("/", 302)
		return
	}

	pid := this.Ctx.Input.Param(":id")
	id, _ := strconv.Atoi(pid)
	problem := models.Problem{Pid: id}
	problem.GetByPid()
	this.Data["problem"] = problem

	testcases := models.Testcases{Pid: id}
	cases, _ := testcases.GetAllByPid()

	this.Data["title"] = "Add Test Case"
	this.Data["cases"] = cases

	this.Layout = "layout.tpl"
	this.TplNames = "problem/addtest.tpl"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHead"] = ""
	this.LayoutSections["Sidebar"] = ""

}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:33,代码来源:ProblemController.go

示例6: ShowEditors

func (this *AdminController) ShowEditors() {
	if !this.isAdmin() {
		return
	}
	user := models.User{}
	users := user.GetEditors()
	bytes, _ := json.Marshal(users)
	this.Data["json"] = string(bytes)
	this.ServeJson()
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:10,代码来源:Admin.go

示例7: RevokeEditor

// /admin/revokeEditor/:uid
func (this *AdminController) RevokeEditor() {
	if !this.isAdmin() {
		return
	}
	uid := this.Ctx.Input.Param("uid")
	user := models.User{}
	id, _ := strconv.Atoi(uid)
	user.Uid = id
	status := user.RevokeEditor()
	this.Data["status"] = status
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:12,代码来源:Admin.go

示例8: SearchName

// /admin/search/name/:name
func (this *AdminController) SearchName() {
	if !this.isAdmin() {
		return
	}
	name := this.Ctx.Input.Param(":name")
	user := models.User{}
	user.Name = name
	users, _ := user.SearchByName()
	bytes, _ := json.Marshal(users)
	this.Data["json"] = string(bytes)
	this.ServeJson()
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:13,代码来源:Admin.go

示例9: SaveProblem

// Save Problem
// To-do: Clean info before save - Ambigous
// To-do: Check login and user previlages - Done
func (this *ProblemController) SaveProblem() {

	if !this.isLoggedIn() {
		this.Redirect("/user/login", 302)
		return
	}

	//Redirect if user doesnt hold editor rights
	id := this.GetSession("id")
	user := models.User{}
	user.Uid = id.(int)
	if !user.IsEditor() {
		this.Redirect("/", 302)
		return
	}

	points, _ := strconv.Atoi(this.GetString("points"))
	//remove replace foe newlines
	sampleInput := strings.Replace(this.GetString("sample_input"), "\r", "", -1)
	sampleOutput := strings.Replace(this.GetString("sample_output"), "\r", "", -1)
	problem := models.Problem{
		Statement:   this.GetString("statement"),
		Description: this.GetString("description"),
		Constraints: this.GetString("constraints"),
		//Sample_input:  this.GetString("sample_input"),
		//Sample_output: this.GetString("sample_output"),
		Type:       this.GetString("type"),
		Difficulty: this.GetString("difficulty"),
		Points:     points,
		Uid:        id.(int),
	}
	problem.Sample_output = sampleOutput
	problem.Sample_input = sampleInput
	id, noerr := problem.Create()
	pid := strconv.Itoa(id.(int))
	if noerr == true {
		this.Redirect("/problem/"+pid, 302)
	}

	this.Data["title"] = "Create Problem "

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

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

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

示例12: Create

// Create Page
func (this *ProblemController) Create() {

	// If not logged redirect to login
	if !this.isLoggedIn() {
		this.Redirect("/user/login", 302)
		return
	}

	//Redirect if user doesnt hold editor rights
	id := this.GetSession("id")
	user := models.User{}
	user.Uid = id.(int)
	if !user.IsEditor() {
		this.Redirect("/", 302)
		return
	}

	this.Data["title"] = "Create Problem "
	this.Layout = "layout.tpl"
	this.TplNames = "problem/create.tpl"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHead"] = ""
	this.LayoutSections["Sidebar"] = ""
}
开发者ID:JRonak,项目名称:OnlineJudge,代码行数:25,代码来源:ProblemController.go

示例13: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。