Golang Request.PostFormValue Examples

Golang Request.PostFormValue - 30 examples found. These are the top rated real world Golang examples of net/http.Request.PostFormValue extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
func ModifyRuleHandler(rw http.ResponseWriter, req *http.Request) {
	var data = make(map[string]interface{})

	if req.PostFormValue("submit") == "1" {
		user, _ := filter.CurrentUser(req)

		errMsg, err := service.ModifyTopic(user, req.PostForm)
		if err != nil {
			data["ok"] = 0
			data["error"] = errMsg
		} else {
			data["ok"] = 1
			data["msg"] = "修改成功"
		}
	} else {
		topic, replies, err := service.FindTopicByTid(req.FormValue("tid"))

		if err != nil {
			rw.WriteHeader(http.StatusInternalServerError)
			return
		}

		// 设置内容模板
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/topic/modify.html")
		data["topic"] = topic
		data["replies"] = replies
		data["nodes"] = service.GenNodes()
	}

	filter.SetData(req, data)
}
Example #2
0
func notificationHandler(w http.ResponseWriter, r *http.Request) {
	bucket, name := r.PostFormValue("bucket"), r.PostFormValue("name")
	if bucket == "" || name == "" {
		http.Error(w, "missing bucket or name", http.StatusBadRequest)
		return
	}

	if ok, err := authorized(r.Header.Get("Authorization")); !ok {
		if err != nil {
			log.Printf("authorize: %v", err)
		}
		http.Error(w, "you're not authorized", http.StatusForbidden)
		return
	}

	start := time.Now()
	defer func() { log.Printf("%v: processed in %v", name, time.Since(start)) }()

	if err := processImage(bucket, name); err != nil {
		// TODO: should this remove uploaded images?
		log.Println(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if err := notifyDone(name); err != nil {
		log.Println(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
Example #3
0
func postRegister(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	username, password := r.PostFormValue("username"), r.PostFormValue("password")
	if !recaptcher.Verify(*r) {
		logger.WithFields(logrus.Fields{
			"user":  username,
			"error": recaptcher.LastError(),
		}).Error("Failed to verify reCaptcha during registration.")
		w.Write([]byte("Failed to verify the reCaptcha. Please verify that you are human and try again."))
		return
	}

	err := users.Register(username, password)
	switch err {
	case nil:
		//Success
		logger.WithFields(logrus.Fields{
			"method": r.Method,
			"url":    r.URL,
			"client": r.RemoteAddr,
			"user":   username,
		}).Info("User registration")
		renderer.Render(w, pages.Get(RegistrationSuccessPage))
	case ErrUserExists:
		http.Error(w, "The user already exists. Please try again with a different username.", http.StatusPreconditionFailed)
	default:
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
// Updates the display-station mapping for a single display.
func FieldPostHandler(w http.ResponseWriter, r *http.Request) {
	displayId := r.PostFormValue("displayId")
	allianceStation := r.PostFormValue("allianceStation")
	mainArena.allianceStationDisplays[displayId] = allianceStation
	mainArena.matchLoadTeamsNotifier.Notify(nil)
	http.Redirect(w, r, "/setup/field", 302)
}
Example #5
0
func viewInvite(w http.ResponseWriter, r *http.Request) {
	mail := r.PostFormValue("mail")
	conf, err := loadConf()
	if err != nil {
		log.Fatalln(err)
	}

	client := &http.Client{}
	data := url.Values{
		"email":      {mail},
		"token":      {conf.Token},
		"set_active": {"true"},
	}

	resp, err := client.Post(
		"https://"+conf.URL+"/api/users.admin.invite",
		"application/x-www-form-urlencoded",
		strings.NewReader(data.Encode()),
	)
	if err != nil {
		log.Fatalln(err)
	}
	body, _ := ioutil.ReadAll(resp.Body)

	var status map[string]interface{}
	json.Unmarshal(body, &status)
	fmt.Println(status["ok"])
	statusOk := fmt.Sprint(status["ok"])

	if statusOk == "true" {
		fmt.Fprintf(w, mail+"に招待状を送信しました.")
	} else {
		fmt.Fprintf(w, "失敗した。失敗した。失敗した。"+fmt.Sprint(status["error"]))
	}
}
Example #6
0
func compile(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-type", "application/json")

	if len(CorsHeader) > 0 {
		w.Header().Set("Access-Control-Allow-Origin", CorsHeader)
	}
	// language := r.PostFormValue("language")
	language := "C#"
	code := r.PostFormValue("code")

	codeSize := len(code)
	if codeSize <= 0 || codeSize > MaximumCodeSizeInBytes {
		compileResponseError(w, "Code must be greater than 0 and less than max limit")
		return
	}

	out, err, elapsed, timedOut := executeCodeOnDocker(language, code)

	compileResponse(
		w,
		out,
		int64(elapsed/time.Millisecond),
		err,
		timedOut)
}