Update main.go
This commit is contained in:
parent
2124051cd3
commit
4c2434415b
206
main.go
206
main.go
@ -14,12 +14,31 @@ import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
//logowanie ------------
|
||||
var loginFROMsite string
|
||||
var passwordFROMsite string
|
||||
var UserView string
|
||||
|
||||
//users ---------------
|
||||
var IDusers int
|
||||
var User string
|
||||
var Password string
|
||||
var PIN int
|
||||
var RFID int
|
||||
var Login string
|
||||
var Blokada bool
|
||||
var Koszt int
|
||||
|
||||
//bilety ---------------
|
||||
var IDbiletu int
|
||||
var KtoZabral string
|
||||
var DataCzas string
|
||||
var KosztBiletu int
|
||||
|
||||
//dania ---------------
|
||||
var IDdania int
|
||||
var NazwaDania string
|
||||
var KosztDania int
|
||||
|
||||
//***************************************************************************
|
||||
//funkcje sterujące
|
||||
@ -35,59 +54,45 @@ func panel(w http.ResponseWriter, r *http.Request) {
|
||||
//Here:
|
||||
//time.Sleep(3 * time.Second)
|
||||
|
||||
/*
|
||||
//bilety ----------------------------------
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
rows1, err := db.Query("SELECT * FROM bilety")
|
||||
checkErr(err)
|
||||
fmt.Fprintf(w, "Lista zabranych biletów: \n")
|
||||
for rows1.Next() {
|
||||
err = rows1.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu)
|
||||
checkErr(err)
|
||||
fmt.Printf("%d. %s, %s, %d \n", IDbiletu, KtoZabral, DataCzas, KosztBiletu)
|
||||
}
|
||||
//----------------------------------
|
||||
//dania ----------------------------------
|
||||
rows2, err := db.Query("SELECT * FROM dania")
|
||||
checkErr(err)
|
||||
fmt.Fprintf(w, "Lista dań: \n")
|
||||
for rows2.Next() {
|
||||
err = rows2.Scan(&IDdania, &NazwaDania, &KosztDania)
|
||||
checkErr(err)
|
||||
fmt.Printf("%d. %s, %d \n", IDdania, NazwaDania, KosztDania)
|
||||
}
|
||||
//----------------------------------
|
||||
rows1.Close()
|
||||
rows2.Close()
|
||||
db.Close()
|
||||
*/
|
||||
|
||||
fmt.Println("method:", r.Method)
|
||||
if r.Method == "GET" {
|
||||
t, _ := template.ParseFiles("panel.gtpl")
|
||||
d := struct {
|
||||
UserView string
|
||||
}{
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "panel.gtpl", d)
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
// query
|
||||
rows, err := db.Query("SELECT * FROM users")
|
||||
checkErr(err)
|
||||
//fmt.Fprintf(w, "Lista użytkowników:\n")
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&IDusers, &User, &Password, &PIN, &RFID, &Login)
|
||||
checkErr(err)
|
||||
//fmt.Printf("%d. %s, %s, %d, %d, %s \n", IDusers, User, Password, PIN, RFID, Login)
|
||||
//fmt.Fprintf(w, "%d. %s \n", IDusers, User)
|
||||
if r.Method == "POST" {
|
||||
if Login == loginFROMsite {
|
||||
if Password == passwordFROMsite {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rows.Close()
|
||||
db.Close()
|
||||
//----------------------------------
|
||||
*/
|
||||
|
||||
//#############################################################################
|
||||
func login(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("method:", r.Method)
|
||||
if r.Method == "GET" {
|
||||
t, _ := template.ParseFiles("login.gtpl")
|
||||
t.Execute(w, nil)
|
||||
} else {
|
||||
r.ParseForm()
|
||||
//fmt.Println("usernameFROMsite: ", r.Form["usernameFROMsite"])
|
||||
//fmt.Println("passwordFROMsite: ", r.Form["passwordFROMsite"])
|
||||
//if len(r.Form["usernameFROMsite"][0]) == 0 {
|
||||
// goto Here
|
||||
//}
|
||||
//if len(r.Form["passwordFROMsite"][0]) == 0 {
|
||||
// goto Here
|
||||
//}
|
||||
}
|
||||
loginFROMsite := r.FormValue("loginFROMsite")
|
||||
passwordFROMsite := r.FormValue("passwordFROMsite")
|
||||
//zaloguj := "Zalogowano!"
|
||||
@ -96,18 +101,18 @@ func login(w http.ResponseWriter, r *http.Request) {
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
// query
|
||||
rows, err := db.Query("SELECT * FROM users")
|
||||
rows0, err := db.Query("SELECT * FROM users")
|
||||
checkErr(err)
|
||||
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&IDusers, &User, &Password, &PIN, &RFID, &Login)
|
||||
for rows0.Next() {
|
||||
err = rows0.Scan(&IDusers, &User, &Password, &PIN, &RFID, &Login, &Blokada, &Koszt)
|
||||
checkErr(err)
|
||||
//fmt.Printf("%d. %s, %s, %d, %d, %s \n", IDusers, User, Password, PIN, RFID, Login)
|
||||
//fmt.Printf("%d. %s, %s, %d, %d, %s, %d, %d \n", IDusers, User, Password, PIN, RFID, Login, Blokada, Koszt)
|
||||
//fmt.Fprint(w, IDusers)
|
||||
//fmt.Fprint(w, ". ")
|
||||
//fmt.Fprint(w, User)
|
||||
//fmt.Fprint(w, " \n")
|
||||
if r.Method == "POST" {
|
||||
//if r.Method == "POST" {
|
||||
if Login == loginFROMsite {
|
||||
if Password == passwordFROMsite {
|
||||
//fmt.Fprintln(w, zaloguj)
|
||||
@ -119,20 +124,123 @@ func login(w http.ResponseWriter, r *http.Request) {
|
||||
break
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
fmt.Println("method:", r.Method)
|
||||
if r.Method == "GET" {
|
||||
t, _ := template.ParseFiles("login.gtpl")
|
||||
t.Execute(w, nil)
|
||||
//} else {
|
||||
r.ParseForm()
|
||||
//fmt.Println("usernameFROMsite: ", r.Form["usernameFROMsite"])
|
||||
//fmt.Println("passwordFROMsite: ", r.Form["passwordFROMsite"])
|
||||
//if len(r.Form["usernameFROMsite"][0]) == 0 {
|
||||
// goto Here
|
||||
//}
|
||||
//if len(r.Form["passwordFROMsite"][0]) == 0 {
|
||||
// goto Here
|
||||
//}
|
||||
}
|
||||
|
||||
//obsługa blędnego wpisania loginu lub hasła
|
||||
if r.Method == "POST" {
|
||||
if loginFROMsite != Login {
|
||||
if loginFROMsite == "" {
|
||||
if passwordFROMsite != Password {
|
||||
t, _ := template.ParseFiles("login.gtpl")
|
||||
t.Execute(w, nil)
|
||||
fmt.Fprint(w, "*** UWAGA! *** Błąd logowania! Login lub hasło nieprawidłowe. *** Spróbuj ponownie. ***")
|
||||
}
|
||||
} else {
|
||||
if passwordFROMsite != Password {
|
||||
t, _ := template.ParseFiles("login.gtpl")
|
||||
t.Execute(w, nil)
|
||||
fmt.Fprint(w, "*** UWAGA! *** Błąd logowania! Login lub hasło nieprawidłowe. *** Spróbuj ponownie. ***")
|
||||
}
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
}
|
||||
}
|
||||
rows0.Close()
|
||||
db.Close()
|
||||
//**************************************************************************
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||
t, _ := template.ParseFiles("historiaPosilkowNaglowek.gtpl")
|
||||
d := struct {
|
||||
UserView string
|
||||
}{
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "historiaPosilkowNaglowek.gtpl", d)
|
||||
|
||||
//bilety ----------------------------------
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
rows3, err := db.Query("SELECT * FROM bilety")
|
||||
checkErr(err)
|
||||
for rows3.Next() {
|
||||
err = rows3.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu)
|
||||
checkErr(err)
|
||||
if KtoZabral == User {
|
||||
t, _ := template.ParseFiles("historiaPosilkow.gtpl")
|
||||
d := struct {
|
||||
IDbiletuView int
|
||||
KtoZabralView string
|
||||
DataCzasView string
|
||||
KosztBiletuView int
|
||||
}{
|
||||
IDbiletuView: IDbiletu,
|
||||
KtoZabralView: KtoZabral,
|
||||
DataCzasView: DataCzas,
|
||||
KosztBiletuView: KosztBiletu}
|
||||
t.ExecuteTemplate(w, "historiaPosilkow.gtpl", d)
|
||||
}
|
||||
//----------------------------------
|
||||
}
|
||||
rows3.Close()
|
||||
db.Close()
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func platnosci(w http.ResponseWriter, r *http.Request) {
|
||||
t, _ := template.ParseFiles("platnosci.gtpl")
|
||||
d := struct {
|
||||
UserView string
|
||||
}{
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "platnosci.gtpl", d)
|
||||
|
||||
//bilety ----------------------------------
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
rows4, err := db.Query("SELECT * FROM bilety")
|
||||
checkErr(err)
|
||||
for rows4.Next() {
|
||||
err = rows4.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu)
|
||||
checkErr(err)
|
||||
if KtoZabral == User {
|
||||
t, _ := template.ParseFiles("platnosci.gtpl")
|
||||
d := struct {
|
||||
IDbiletuView int
|
||||
KtoZabralView string
|
||||
DataCzasView string
|
||||
KosztBiletuView int
|
||||
}{
|
||||
IDbiletuView: IDbiletu,
|
||||
KtoZabralView: KtoZabral,
|
||||
DataCzasView: DataCzas,
|
||||
KosztBiletuView: KosztBiletu}
|
||||
t.ExecuteTemplate(w, "platnosci.gtpl", d)
|
||||
}
|
||||
//----------------------------------
|
||||
}
|
||||
rows4.Close()
|
||||
db.Close()
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
//Bazy danych SQlite
|
||||
//***************************************************************************
|
||||
@ -150,6 +258,8 @@ func main() {
|
||||
http.HandleFunc("/", opisStołówkaZPM)
|
||||
http.HandleFunc("/login", login)
|
||||
http.HandleFunc("/panel", panel)
|
||||
http.HandleFunc("/historiaPosilkow", historiaPosilkow)
|
||||
http.HandleFunc("/platnosci", platnosci)
|
||||
|
||||
err := http.ListenAndServe(":9197", nil)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user