func (b BoxGoalGenerator) HandleForm(c web.C, writer http.ResponseWriter, request *http.Request) { request.ParseForm() form := request.Form username := form.Get("username") skill := form.Get("skill") goal := form.Get("goal") hide_username := form.Get("hide") if hide_username == "on" && util.AES_KEY != nil { name, err := util.Encrypt(username) if err == nil { name = "_" + name } username = name } // todo: validate input? url := fmt.Sprintf("/%s/%s/%s", username, skill, goal) util.ServeResultPage(c, writer, request, url) }
func (m MultiGoalGenerator) HandleForm(c web.C, writer http.ResponseWriter, request *http.Request) { request.ParseForm() form := request.Form username := form.Get("username") // Workaround to preserve order var buf bytes.Buffer for id := 0; id < len(util.Skills); id++ { skill := form.Get("skill_" + strconv.Itoa(id)) goal := form.Get("goal_" + strconv.Itoa(id)) if skill == "" || goal == "" { continue } if _, err := util.GetSkillByName(skill); err != nil { continue } queryPrefix := url.QueryEscape(skill) + "=" if buf.Len() > 0 { buf.WriteByte('&') } buf.WriteString(queryPrefix) buf.WriteString(url.QueryEscape(goal)) } hide_username := form.Get("hide") if hide_username == "on" && util.AES_KEY != nil && len(util.AES_KEY) > 0 { name, err := util.Encrypt(username) if err == nil { name = "_" + name } username = name } hash := buf.String() url := fmt.Sprintf("/multi/%s?%s", username, hash) util.ServeResultPage(c, writer, request, url) }