|
@@ -4,6 +4,7 @@ import (
|
|
|
//"html/template"
|
|
|
"net/http"
|
|
|
"fmt"
|
|
|
+ "strconv"
|
|
|
)
|
|
|
|
|
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|
@@ -72,7 +73,8 @@ func logInPostHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
r.ParseForm()
|
|
|
username := r.PostForm.Get("username")
|
|
|
password := r.PostForm.Get("password")
|
|
|
-
|
|
|
+ fmt.Printf("Post from website! r.PostFrom = %v\n", r.PostForm)
|
|
|
+
|
|
|
if (dBConnector.LogIn(username, password)){
|
|
|
|
|
|
session, _ := sessionsStore.Get(r, "session")
|
|
@@ -80,7 +82,6 @@ func logInPostHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
session.Values["password"] = password
|
|
|
|
|
|
session.Save(r,w)
|
|
|
- fmt.Printf("%s\n%s\n",username,password)
|
|
|
http.Redirect(w, r, "/", http.StatusFound)
|
|
|
} else {
|
|
|
data := struct {
|
|
@@ -96,6 +97,7 @@ func logInPostHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
logInTemplate.Execute(w, data)
|
|
|
//w.Write([]byte("Login error"))
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func logOutGetHandler(w http.ResponseWriter, r *http.Request) {
|
|
@@ -168,7 +170,16 @@ func gamePostHandler(w http.ResponseWriter, r *http.Request){ //TODO запис
|
|
|
return
|
|
|
}
|
|
|
fmt.Printf("Post from website! r.PostFrom = %v\n", r.PostForm)
|
|
|
- score := r.FormValue("score")
|
|
|
- fmt.Fprintf(w,"score = %s\n", score)
|
|
|
- fmt.Printf("score = %s\n", score)
|
|
|
+ score_str := r.FormValue("score")
|
|
|
+ fmt.Fprintf(w,"score = %s\n", score_str)
|
|
|
+ fmt.Printf("score = %s\n", score_str)
|
|
|
+ score_int, err := strconv.Atoi(score_str)
|
|
|
+ if err != nil {
|
|
|
+ // handle error
|
|
|
+ fmt.Println(err)
|
|
|
+ logger.Printf("Error extracting score from '%s'",score_str)
|
|
|
+ //os.Exit(2)
|
|
|
+ } else {
|
|
|
+ dBConnector.SubmitScore(score_int)
|
|
|
+ }
|
|
|
}
|