diff --git a/main.go b/main.go index 3491023..0358a48 100644 --- a/main.go +++ b/main.go @@ -59,8 +59,8 @@ func login(w http.ResponseWriter, r *http.Request) { t.Execute(w, nil) } else { r.ParseForm() - fmt.Println("usernameFROMsite: ", r.Form["usernameFROMsite"]) - fmt.Println("passwordFROMsite: ", r.Form["passwordFROMsite"]) + //fmt.Println("usernameFROMsite: ", r.Form["usernameFROMsite"]) + //fmt.Println("passwordFROMsite: ", r.Form["passwordFROMsite"]) //if len(r.Form["usernameFROMsite"][0]) == 0 { // goto Here //} @@ -68,16 +68,51 @@ func login(w http.ResponseWriter, r *http.Request) { // goto Here //} } - usernameFROMsite := r.Form["usernameFROMsite"] - passwordFROMsite := r.Form["passwordFROMsite"] - zaloguj := "Wpisane wartości:" - if r.Method == "POST" { - if zaloguj == "Wpisane wartości:" { - fmt.Fprintln(w, zaloguj) - fmt.Fprintln(w, usernameFROMsite) - fmt.Fprintln(w, passwordFROMsite) + usernameFROMsite := r.FormValue("usernameFROMsite") + passwordFROMsite := r.FormValue("passwordFROMsite") + zaloguj := "Zalogowano!" + + //*************************************************************************** + db, err := sql.Open("sqlite3", "stolowkaZPM.db") + checkErr(err) + // query + rows, err := db.Query("SELECT * FROM users") + checkErr(err) + var IDusers int + var User string + var Password string + var PIN int + var RFID int + + for rows.Next() { + err = rows.Scan(&IDusers, &User, &Password, &PIN, &RFID) + checkErr(err) + //fmt.Printf("%d. %s, %s, %d, %d \n", IDusers, User, Password, PIN, RFID) + //fmt.Fprint(w, IDusers) + //fmt.Fprint(w, ". ") + //fmt.Fprint(w, User) + //fmt.Fprint(w, " \n") + if r.Method == "POST" { + if User == usernameFROMsite { + if Password == passwordFROMsite { + fmt.Fprintln(w, zaloguj) + fmt.Fprintln(w, usernameFROMsite) + fmt.Fprintln(w, passwordFROMsite) + break + } + } } } + if r.Method == "POST" { + if usernameFROMsite != User { + t, _ := template.ParseFiles("login.gtpl") + t.Execute(w, nil) + fmt.Fprint(w, "*** UWAGA! *** Błąd logowania! *** Spróbuj ponownie. ***") + } + } + rows.Close() + db.Close() + //*************************************************************************** } //***************************************************************************