Esempio n. 1
0
func submitTeamHandler(w http.ResponseWriter, r *http.Request) {
	//data := setDefaultData(w, r)
	//submission := make(map[string]interface{})
	// **TOP
	r.ParseForm()
	teamMembers := r.Form["teamEmails"]

	newContest := role.FindContests()
	currentContest := role.FindContest(newContest[0].Id.Hex())

	teamContainer := make([]*user.User, 0)
	for i := 0; i < len(teamMembers); i++ {
		newUser := user.FindUser(teamMembers[i])
		teamContainer = append(teamContainer, newUser)
	}

	teamId := bson.NewObjectId()
	//s := redis_session.Session(w, r)

	// ****** CLEANING ********
	newTeam := role.NewTeam(teamContainer, r.FormValue("teamName"), r.FormValue("motto"), teamId)

	role.InsertNewTeam(newTeam)

	currentContest.InsertTeam(newTeam)

	//data["contests"] = currentContest
	http.Redirect(w, r, "/teams/browse", http.StatusTemporaryRedirect)
}
Esempio n. 2
0
func browseTeamsHandler(w http.ResponseWriter, r *http.Request) {
	data := setDefaultData(w, r)

	newContest := role.FindContests()
	contestList := role.FindContest(newContest[0].Id.Hex())

	fmt.Println(contestList)

	data["contests"] = contestList

	display(w, "browseTeams", &Page{Title: "Teams", Data: data})
}
Esempio n. 3
0
func contestMainHandler(w http.ResponseWriter, r *http.Request) {
	s := redis_session.Session(w, r)
	currentUser := user.FindUser(s.Get("Email"))
	data := setDefaultData(w, r)

	// newContest := role.FindContests()
	// currentContest := role.FindContest(newContest[0].Id.Hex())

	contestId := r.URL.Query().Get("id")
	if contestId == "" {
		newContest := role.FindContests()
		contestId = newContest[0].Id.Hex()
	}
	contest := role.FindContest(contestId)
	data["contest"] = contest
	data["user"] = currentUser
	display(w, "viewContest", &Page{Title: "Contest", Data: data})
}