From 47e06e8de9cc6a55791fd5b1cea14f97a245bab2 Mon Sep 17 00:00:00 2001 From: Emile Date: Sat, 19 Oct 2019 18:28:39 +0200 Subject: correctly parsing the http form creating the new challenge --- src/http.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/http.go b/src/http.go index 721ceb1..630f9a6 100644 --- a/src/http.go +++ b/src/http.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "log" "net/http" + "strconv" "strings" "github.com/gorilla/mux" @@ -53,6 +54,22 @@ func createPostHandler(w http.ResponseWriter, r *http.Request) { // parse the Post Request form r.ParseForm() + points, err := strconv.ParseInt(r.Form.Get("challengePoints"), 10, 64) + if err != nil { + log.Println("Could not parse points: %v", err) + return + } + + var static bool + if r.Form.Get("challengeStatic") == "on" { + static = true + } else if r.Form.Get("challengeStatic") == "off" { + static = false + } else { + log.Println("Could not parse static: %v", r.Form.Get("challengeStatic")) + return + } + // Define the new challenge newChallenge := Challenge{ Name: r.Form.Get("challengeName"), @@ -60,14 +77,15 @@ func createPostHandler(w http.ResponseWriter, r *http.Request) { Flag: r.Form.Get("challengeFlag"), Container: r.Form.Get("challengeContainer"), Category: r.Form.Get("challengeCategory"), - Points: r.Form.Get("challengePoints"), - Static: r.Form.Get("challengeStatic"), + Points: int(points), + Static: static, } // Create the new challenge in the database - err := newChallenge(newChallenge) + err = dbNewChallenge(newChallenge) if err != nil { log.Println(err) + return } } -- cgit 1.4.1