about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-19 18:28:39 +0200
committerEmile <hanemile@protonmail.com>2019-10-19 18:28:39 +0200
commit47e06e8de9cc6a55791fd5b1cea14f97a245bab2 (patch)
treed720f586963f26476d05af4c0cafb1c5fc9dacb0 /src
parent9078b7429abc1b567bf4bc7e8b9466655ce9ebb1 (diff)
correctly parsing the http form creating the new challenge
Diffstat (limited to 'src')
-rw-r--r--src/http.go24
1 files changed, 21 insertions, 3 deletions
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
 	}
 }