Beispiel #1
0
func poplop_handle(w http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	nick := req.Form.Get("nickname")
	master := req.Form.Get("master")
	if nick == "" || master == "" {
		http.Error(w, "Both nickname and master parameters are required", http.StatusBadRequest)
		return
	}

	n, err := db.GetScheme(nick)
	if err != nil && err != sql.ErrNoRows {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if err == sql.ErrNoRows {
		http.Error(w, "Nickname not found", http.StatusNotFound)
		return
	}

	pass, err := n.Hash(master)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	io.WriteString(w, pass)
}
Beispiel #2
0
func scheme_get(w http.ResponseWriter, req *http.Request) {
	dir, name := path.Split(req.URL.Path)
	if dir != "/scheme/" {
		http.Error(w, "Unknown directory structure", http.StatusBadRequest)
		return
	}

	n, err := db.GetScheme(name)
	if err != nil && err != sql.ErrNoRows {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if err == sql.ErrNoRows {
		http.Error(w, "name not found", http.StatusNotFound)
		return
	}

	err = json.NewEncoder(w).Encode(n)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}