Update main.go

This commit is contained in:
s441433 2018-12-29 04:11:48 +01:00
parent 977dfbe4c5
commit 51b02276b8

47
main.go
View File

@ -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,17 +68,52 @@ func login(w http.ResponseWriter, r *http.Request) {
// goto Here
//}
}
usernameFROMsite := r.Form["usernameFROMsite"]
passwordFROMsite := r.Form["passwordFROMsite"]
zaloguj := "Wpisane wartości:"
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 zaloguj == "Wpisane wartości:" {
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()
//***************************************************************************
}
//***************************************************************************
//Bazy danych SQlite