Update main.go
This commit is contained in:
parent
7eb099a017
commit
f5580e86e4
181
main.go
181
main.go
@ -14,39 +14,50 @@ import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
//logowanie ------------
|
||||
var loginFROMsite string
|
||||
var passwordFROMsite string
|
||||
var (
|
||||
//localhost-------------
|
||||
ID int
|
||||
localHostDB string
|
||||
localHost 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
|
||||
//logowanie ------------
|
||||
loginFROMsite string
|
||||
passwordFROMsite string
|
||||
|
||||
//bilety ---------------
|
||||
var IDbiletu int
|
||||
var KtoZabral string
|
||||
var DataCzas string
|
||||
var KosztBiletu int
|
||||
var CzyZaplacony bool
|
||||
//users ---------------
|
||||
IDusers int
|
||||
User string
|
||||
Password string
|
||||
PIN int
|
||||
RFID int
|
||||
Login string
|
||||
Blokada bool
|
||||
Koszt int
|
||||
|
||||
//dania ---------------
|
||||
var IDdania int
|
||||
var NazwaDania string
|
||||
var KosztDania int
|
||||
//bilety ---------------
|
||||
IDbiletu int
|
||||
KtoZabral string
|
||||
DataCzas string
|
||||
KosztBiletu int
|
||||
CzyZaplacony bool
|
||||
|
||||
//dania ---------------
|
||||
IDdania int
|
||||
NazwaDania string
|
||||
KosztDania int
|
||||
)
|
||||
|
||||
//const localHost = string("192.168.8.102:9197")
|
||||
|
||||
//***************************************************************************
|
||||
//funkcje sterujące
|
||||
//***************************************************************************
|
||||
|
||||
//#############################################################################
|
||||
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
|
||||
//fmt.Println(localHostDB)
|
||||
t, _ := template.ParseFiles("StronaGlowna.gtpl")
|
||||
t.Execute(w, nil)
|
||||
t.Execute(w, localHost)
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
@ -88,9 +99,11 @@ func panel(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("method:", r.Method)
|
||||
t, _ := template.ParseFiles("panel.gtpl")
|
||||
d := struct {
|
||||
UserView string
|
||||
UserView string
|
||||
localHostView string
|
||||
}{
|
||||
UserView: User}
|
||||
UserView: User,
|
||||
localHostView: localHost}
|
||||
t.ExecuteTemplate(w, "panel.gtpl", d)
|
||||
}
|
||||
|
||||
@ -100,6 +113,7 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
//--------------------------------------------------
|
||||
t, _ := template.ParseFiles("wylogowano.gtpl")
|
||||
d := struct {
|
||||
localHostView string
|
||||
loginFROMsiteView string
|
||||
passwordFROMsiteView string
|
||||
IDusersView int
|
||||
@ -118,6 +132,7 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
NazwaDaniaView string
|
||||
KosztDaniaView int
|
||||
}{
|
||||
localHostView: localHost,
|
||||
loginFROMsiteView: "",
|
||||
passwordFROMsiteView: "",
|
||||
IDusersView: 0,
|
||||
@ -141,18 +156,18 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
//#############################################################################
|
||||
func login(w http.ResponseWriter, r *http.Request) {
|
||||
//fmt.Println(localHost)
|
||||
//cookies start===================================================================
|
||||
type Cookie struct {
|
||||
Login string
|
||||
Password string
|
||||
}
|
||||
//type Cookie struct {
|
||||
// Login string
|
||||
// Password string
|
||||
//}
|
||||
//cookies end===================================================================
|
||||
|
||||
//**************************************************************************
|
||||
loginFROMsite := r.FormValue("loginFROMsite")
|
||||
passwordFROMsite := r.FormValue("passwordFROMsite")
|
||||
//zaloguj := "Zalogowano!"
|
||||
|
||||
//**************************************************************************
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
// query
|
||||
@ -179,56 +194,109 @@ func login(w http.ResponseWriter, r *http.Request) {
|
||||
break
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
fmt.Println("method:", r.Method)
|
||||
//fmt.Println("method:", r.Method)
|
||||
//r.Method = "GET"
|
||||
if r.Method == "GET" {
|
||||
t, _ := template.ParseFiles("login.gtpl")
|
||||
t.Execute(w, nil)
|
||||
//} else {
|
||||
d := struct {
|
||||
localHost string
|
||||
}{
|
||||
localHost: localHost}
|
||||
t.ExecuteTemplate(w, "login.gtpl", d)
|
||||
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
|
||||
//}
|
||||
}
|
||||
|
||||
//} else {
|
||||
//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)
|
||||
d := struct {
|
||||
localHostView string
|
||||
}{
|
||||
localHostView: localHost}
|
||||
t.ExecuteTemplate(w, "login.gtpl", d)
|
||||
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)
|
||||
d := struct {
|
||||
localHostView string
|
||||
}{
|
||||
localHostView: localHost}
|
||||
t.ExecuteTemplate(w, "login.gtpl", d)
|
||||
fmt.Fprint(w, "*** UWAGA! *** Błąd logowania! Login lub hasło nieprawidłowe. *** Spróbuj ponownie. ***")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//**************************************************************************
|
||||
rows0.Close()
|
||||
db.Close()
|
||||
//**************************************************************************
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func menuDan(w http.ResponseWriter, r *http.Request) {
|
||||
t, _ := template.ParseFiles("menuDanNaglowek.gtpl")
|
||||
d := struct {
|
||||
localHostView string
|
||||
UserView string
|
||||
}{
|
||||
localHostView: localHost,
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "menuDanNaglowek.gtpl", d)
|
||||
//dania ----------------------------------
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr2(err)
|
||||
rows2, err := db.Query("SELECT * FROM dania")
|
||||
checkErr(err)
|
||||
for rows2.Next() {
|
||||
err = rows2.Scan(&IDdania, &NazwaDania, &KosztDania)
|
||||
checkErr3(err)
|
||||
//fmt.Printf("%d. %s, %d \n", IDdania, NazwaDania, KosztDania)
|
||||
t, _ := template.ParseFiles("menuDan.gtpl")
|
||||
d := struct {
|
||||
localHostView string
|
||||
IDdaniaView int
|
||||
NazwaDaniaView string
|
||||
KosztDaniaView int
|
||||
}{
|
||||
localHostView: localHost,
|
||||
IDdaniaView: IDdania,
|
||||
NazwaDaniaView: NazwaDania,
|
||||
KosztDaniaView: KosztDania}
|
||||
t.ExecuteTemplate(w, "menuDan.gtpl", d)
|
||||
}
|
||||
//----------------------------------
|
||||
rows2.Close()
|
||||
db.Close()
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||
t, _ := template.ParseFiles("historiaPosilkowNaglowek.gtpl")
|
||||
d := struct {
|
||||
UserView string
|
||||
localHostView string
|
||||
UserView string
|
||||
}{
|
||||
UserView: User}
|
||||
localHostView: localHost,
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "historiaPosilkowNaglowek.gtpl", d)
|
||||
|
||||
//bilety ----------------------------------
|
||||
@ -242,12 +310,14 @@ func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||
if KtoZabral == User {
|
||||
t, _ := template.ParseFiles("historiaPosilkow.gtpl")
|
||||
d := struct {
|
||||
localHostView string
|
||||
IDbiletuView int
|
||||
KtoZabralView string
|
||||
DataCzasView string
|
||||
KosztBiletuView int
|
||||
CzyZaplaconyView bool
|
||||
}{
|
||||
localHostView: localHost,
|
||||
IDbiletuView: IDbiletu,
|
||||
KtoZabralView: KtoZabral,
|
||||
DataCzasView: DataCzas,
|
||||
@ -323,14 +393,27 @@ func checkErr3(err error) {
|
||||
//funkcja główna
|
||||
//***************************************************************************
|
||||
func main() {
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
rowsHost, err := db.Query("SELECT * FROM localhost")
|
||||
checkErr2(err)
|
||||
for rowsHost.Next() {
|
||||
err = rowsHost.Scan(&ID, &localHostDB)
|
||||
checkErr3(err)
|
||||
}
|
||||
localHost = localHostDB
|
||||
rowsHost.Close()
|
||||
db.Close()
|
||||
|
||||
http.HandleFunc("/", opisStołówkaZPM)
|
||||
http.HandleFunc("/login", login)
|
||||
http.HandleFunc("/panel", panel)
|
||||
http.HandleFunc("/historiaPosilkow", historiaPosilkow)
|
||||
http.HandleFunc("/platnosci", platnosci)
|
||||
http.HandleFunc("/wylogowano", wylogowano)
|
||||
http.HandleFunc("/menuDan", menuDan)
|
||||
|
||||
err := http.ListenAndServe(":9197", nil)
|
||||
err = http.ListenAndServe(":9197", nil)
|
||||
if err != nil {
|
||||
log.Fatal("ListenAndServe: ", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user