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 /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)
}