Esempio n. 1
0
// @router /puzzle/:id:int [post]
func (c *PuzzleController) PuzzlePostId() {
	var id int
	c.Ctx.Input.Bind(&id, ":id")
	check_res := c.checkPuzzleUser(id)
	if check_res < 2 {
		c.Redirect(fmt.Sprintf("/oj/%d", id), 302)
		return
	}

	var puzzle models.Puzzle
	err := c.ParseForm(&puzzle)
	puzzle.Id = id
	var puzzle_old models.Puzzle
	models.ORM.QueryTable((*models.Puzzle)(nil)).Filter("Id", id).One(&puzzle_old)
	puzzle.User = puzzle_old.User
	if check_res != 3 { // 管理员
		puzzle.Online = 0
	}
	if !goutils.CheckErr(err) {
		n, err := models.ORM.Update(&puzzle)
		beego.Debug(n, err)
	}
	fmt.Println(puzzle)
	c.Redirect(fmt.Sprintf("/oj/%d", id), 302)
}
Esempio n. 2
0
// @router /oj/:id:int [get]
func (c *ListController) GetPro() {
	var id int
	c.Ctx.Input.Bind(&id, ":id")
	var puzzle models.Puzzle
	puzzle.Id = id // 为了在页面上渲染
	if ojCheck(id) <= 0 {
		c.Data["Content"] = template.HTML("<h3>题目还未审核,如有问题,请联系管理员。</h3>")
		c.Data["puzzle"] = puzzle
		c.TplName = "sorry.html"
		return
	}
	errq := models.ORM.QueryTable((*models.Puzzle)(nil)).Filter("Id", id).RelatedSel().One(&puzzle)
	goutils.CheckErr(errq)
	c.Data["puzzle"] = puzzle
	addrsplit := strings.Split(c.Ctx.Request.RemoteAddr, ":")
	rid := addrsplit[len(addrsplit)-1]
	c.Data["rid"] = rid
	c.Data["title"] = "Probs"
	c.TplName = "oj.html"
}
Esempio n. 3
0
// @router /puzzle [post]
func (c *PuzzleController) PuzzlePost_New() {
	var puzzle models.Puzzle
	err := c.ParseForm(&puzzle)
	puzzle.Id = 0
	if !goutils.CheckErr(err) {
		puzzle.User = c.CurUser()
		if puzzle.User == nil || puzzle.User.Id != 1 { // 管理员
			puzzle.Online = 0
		}
		if puzzle.User == nil {
			puzzle.User = models.UserByName("Anonymous")
		}
		fmt.Printf("%#v\n", puzzle.User)
		n, err := models.ORM.Insert(&puzzle)
		if !goutils.CheckErr(err) {
			c.Redirect(fmt.Sprintf("/oj/%d", n), 302)
		}
		beego.Debug(n, err)
	}
	fmt.Println(puzzle)
	c.Redirect("/", 302)
}