func ServeContest(w http.ResponseWriter, r *http.Request) { cnt, err := data.GetContest() catch(err) err = json.NewEncoder(w).Encode(cnt) catch(err) }
func ServeProblemBySlug(w http.ResponseWriter, r *http.Request) { cnt, err := data.GetContest() catch(err) me, _ := context.Get(r, "me").(*data.Account) if !cnt.Started() && (me == nil || (me.Level != data.Judge && me.Level != data.Administrator)) { http.Error(w, "", http.StatusNotFound) return } prob, err := data.GetProblemBySlug(r.FormValue("slug")) catch(err) err = json.NewEncoder(w).Encode(prob) catch(err) }
func ServeProblemList(w http.ResponseWriter, r *http.Request) { cnt, err := data.GetContest() catch(err) me, _ := context.Get(r, "me").(*data.Account) if !cnt.Started() && (me == nil || (me.Level != data.Judge && me.Level != data.Administrator)) { err = json.NewEncoder(w).Encode([]*data.Problem{}) catch(err) return } probs, err := data.ListProblems() catch(err) err = json.NewEncoder(w).Encode(probs) catch(err) }
func ServeProblem(w http.ResponseWriter, r *http.Request) { cnt, err := data.GetContest() catch(err) me, _ := context.Get(r, "me").(*data.Account) if !cnt.Started() && (me == nil || (me.Level != data.Judge && me.Level != data.Administrator)) { http.Error(w, "", http.StatusNotFound) return } vars := mux.Vars(r) id, err := strconv.ParseInt(vars["id"], 10, 64) catch(err) prob, err := data.GetProblem(id) catch(err) err = json.NewEncoder(w).Encode(prob) catch(err) }
func UpdateContest(w http.ResponseWriter, r *http.Request) { me, _ := context.Get(r, "me").(*data.Account) if me == nil || me.Level != data.Administrator { http.Error(w, "", http.StatusForbidden) return } cnt, err := data.GetContest() catch(err) err = json.NewDecoder(r.Body).Decode(cnt) catch(err) err = cnt.Put() catch(err) err = json.NewEncoder(w).Encode(cnt) catch(err) hub.Send([]interface{}{"SYNC", "contest"}) err = data.NewActivity(me, fmt.Sprintf("updated contest %d", cnt.Id)).Put() catch(err) hub.Send([]interface{}{"SYNC", "activities"}) }
func init() { cnt, err := data.GetContest() catch(err) Store = sessions.NewCookieStore(cnt.Salt, cnt.Salt) }