コード例 #1
0
// /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
}
コード例 #2
0
ファイル: Admin.go プロジェクト: JRonak/OnlineJudge
// /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
}
コード例 #3
0
// 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"
}
コード例 #4
0
// 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"] = ""
}
コード例 #5
0
// 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"] = ""
}