// @router /callback [get] func (c *RegistController) Callback() { req := c.Ctx.Request fmt.Printf("%s\n", req.RemoteAddr) b, token, err := OA.NextStepWithToken(req) if nil != err { usr := models.User{Name: "Anonymous", Passwd: "Anonymous"} //存在安全漏洞 n := models.RegisterUser(&usr) if n <= 0 { usr := models.UserByName(usr.Name) n = usr.Id } c.LoginSetSession(n) c.Redirect("/", 302) return } jv := jsnm.BytesFmt(b) name := jv.Get("login").RawData().String() usr := models.User{} usr.Name = name usr.Passwd = token n := models.RegisterUser(&usr) if n <= 0 { usr := models.UserByName(usr.Name) n = usr.Id go func() { usr.Passwd = token _, err := models.ORM.Update(usr) goutils.CheckErr(err) }() c.LoginSetSession(n) c.Redirect("/user", 302) return } c.LoginSetSession(n) c.Redirect("/", 302) }
// @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) }
// @router /oj/:id:int [post] func (c *ListController) OJ() { var id int c.Ctx.Input.Bind(&id, ":id") if ojCheck(id) <= 0 { c.Data["Content"] = template.HTML("<h3>题目还未审核,如有问题,请联系管理员。</h3>") c.TplName = "sorry.html" return } fid := c.GetString("fid") path_ := c.GetString("rid") content := c.GetString("puzzle") if strings.Contains(content, `"os`) { c.Ctx.ResponseWriter.Write(goutils.ToByte("呵呵")) return } beego.Debug(content, path_, fid) // inser into db slt := models.Solution{} cur := c.SessionController.CurUser() if cur != nil { slt.User = &models.User{Id: cur.Id} //models.UserById(cur.Id) } else { slt.User = models.UserByName("Anonymous") } slt.Content = content // slt.Create = *goutils.LocNow("Asia/Shanghai") // fmt.Println(slt) ffid, _ := c.GetInt("fid") slt.Puzzle = &models.Puzzle{Id: ffid} n, dberr := models.ORM.Insert(&slt) if goutils.CheckErr(dberr) { } // insert into db submit_LOCKER.Lock() defer submit_LOCKER.Unlock() cmd := exc.NewCMD("go test -v").Cd(defaultpath) var puzzle models.Puzzle models.ORM.QueryTable((*models.Puzzle)(nil)).Filter("Id", id).One(&puzzle) m := Puzzle2Model(&puzzle) m.Content = content beego.Info(m) err := model_util.GenerateOjModle(path_, m) goutils.CheckErr(err) submitID++ test_result, err := cmd.Wd().Cd(path_).Debug().Do() analyse_result := utils.Analyse(goutils.ToString(test_result)) fmt.Println(analyse_result) goutils.CheckErr(err) if n > 0 { result := models.AnalyseResultParse(analyse_result) m, err := models.ORM.Insert(result) if !goutils.CheckErr(err) { result.Id = int(m) } slt.Result = result slt.Id = int(n) go func() { models.ORM.Update(&slt) }() } go cmd.Reset(fmt.Sprintf("rm -rf %s", path_)).Cd(defaultpath).Execute() c.Ctx.ResponseWriter.Write(goutils.ToByte(analyse_result.String())) }