Esempio n. 1
0
// 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")
	}
}
Esempio n. 2
0
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"] = ""

}
Esempio n. 3
0
func (this *ProblemController) Test() {
	pid := 1
	problem := models.Problem{Pid: pid}
	problem.GetByPid()
	code := this.GetString("code")
	lang := this.GetString("language")
	stdin := this.GetString("stdin")
	output := models.Exec(pid, code, lang, stdin)
	js, _ := json.Marshal(output)
	this.Data["json"] = string(js)
	this.ServeJson()
}
Esempio n. 4
0
func (this *ProblemController) RunCode() {
	if !this.isLoggedIn() {
		this.Redirect("/user/login", 302)
		return
	}

	//uid := this.GetSession("id")
	pid, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
	problem := models.Problem{Pid: pid}
	problem.GetByPid()
	code := this.GetString("code")
	lang := this.GetString("language")
	stdin := this.GetString("stdin")
	output := models.Exec(pid, code, lang, stdin)
	js, _ := json.Marshal(output)
	this.Data["json"] = string(js)
	this.ServeJson()
}