Update main.go
This commit is contained in:
parent
cf1b56b21d
commit
711c328202
131
main.go
131
main.go
@ -17,7 +17,6 @@ import (
|
||||
//logowanie ------------
|
||||
var loginFROMsite string
|
||||
var passwordFROMsite string
|
||||
var UserView string
|
||||
|
||||
//users ---------------
|
||||
var IDusers int
|
||||
@ -34,6 +33,7 @@ var IDbiletu int
|
||||
var KtoZabral string
|
||||
var DataCzas string
|
||||
var KosztBiletu int
|
||||
var CzyZaplacony bool
|
||||
|
||||
//dania ---------------
|
||||
var IDdania int
|
||||
@ -81,6 +81,9 @@ func panel(w http.ResponseWriter, r *http.Request) {
|
||||
rows2.Close()
|
||||
db.Close()
|
||||
*/
|
||||
for _, cookie := range r.Cookies() {
|
||||
fmt.Fprint(w, cookie.Name)
|
||||
}
|
||||
|
||||
fmt.Println("method:", r.Method)
|
||||
t, _ := template.ParseFiles("panel.gtpl")
|
||||
@ -91,8 +94,60 @@ func panel(w http.ResponseWriter, r *http.Request) {
|
||||
t.ExecuteTemplate(w, "panel.gtpl", d)
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
//--------------------------------------------------
|
||||
t, _ := template.ParseFiles("wylogowano.gtpl")
|
||||
d := struct {
|
||||
loginFROMsiteView string
|
||||
passwordFROMsiteView string
|
||||
IDusersView int
|
||||
UserView string
|
||||
PasswordView string
|
||||
PINView int
|
||||
RFIDView int
|
||||
LoginView string
|
||||
BlokadaView bool
|
||||
KosztView int
|
||||
IDbiletuView int
|
||||
KtoZabralView string
|
||||
DataCzasView string
|
||||
KosztBiletuView int
|
||||
IDdaniaView int
|
||||
NazwaDaniaView string
|
||||
KosztDaniaView int
|
||||
}{
|
||||
loginFROMsiteView: "",
|
||||
passwordFROMsiteView: "",
|
||||
IDusersView: 0,
|
||||
UserView: "",
|
||||
PasswordView: "",
|
||||
PINView: 0,
|
||||
RFIDView: 0,
|
||||
LoginView: "",
|
||||
BlokadaView: Blokada,
|
||||
KosztView: 0,
|
||||
IDbiletuView: 0,
|
||||
KtoZabralView: "",
|
||||
DataCzasView: "",
|
||||
KosztBiletuView: 0,
|
||||
IDdaniaView: 0,
|
||||
NazwaDaniaView: "",
|
||||
KosztDaniaView: 0}
|
||||
|
||||
t.ExecuteTemplate(w, "wylogowano.gtpl", d)
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func login(w http.ResponseWriter, r *http.Request) {
|
||||
//cookies start===================================================================
|
||||
type Cookie struct {
|
||||
Login string
|
||||
Password string
|
||||
}
|
||||
//cookies end===================================================================
|
||||
|
||||
loginFROMsite := r.FormValue("loginFROMsite")
|
||||
passwordFROMsite := r.FormValue("passwordFROMsite")
|
||||
//zaloguj := "Zalogowano!"
|
||||
@ -182,20 +237,22 @@ func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||
rows3, err := db.Query("SELECT * FROM bilety")
|
||||
checkErr(err)
|
||||
for rows3.Next() {
|
||||
err = rows3.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu)
|
||||
err = rows3.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
||||
checkErr(err)
|
||||
if KtoZabral == User {
|
||||
t, _ := template.ParseFiles("historiaPosilkow.gtpl")
|
||||
d := struct {
|
||||
IDbiletuView int
|
||||
KtoZabralView string
|
||||
DataCzasView string
|
||||
KosztBiletuView int
|
||||
IDbiletuView int
|
||||
KtoZabralView string
|
||||
DataCzasView string
|
||||
KosztBiletuView int
|
||||
CzyZaplaconyView bool
|
||||
}{
|
||||
IDbiletuView: IDbiletu,
|
||||
KtoZabralView: KtoZabral,
|
||||
DataCzasView: DataCzas,
|
||||
KosztBiletuView: KosztBiletu}
|
||||
IDbiletuView: IDbiletu,
|
||||
KtoZabralView: KtoZabral,
|
||||
DataCzasView: DataCzas,
|
||||
KosztBiletuView: KosztBiletu,
|
||||
CzyZaplaconyView: CzyZaplacony}
|
||||
t.ExecuteTemplate(w, "historiaPosilkow.gtpl", d)
|
||||
}
|
||||
//----------------------------------
|
||||
@ -206,43 +263,44 @@ func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
//#############################################################################
|
||||
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)
|
||||
//fmt.Fprint(w, User)
|
||||
|
||||
//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)
|
||||
rows5, err := db.Query("SELECT SUM(KosztBiletu)FROM bilety WHERE KtoZabral=?", User)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// os.Exit(1)
|
||||
}
|
||||
/*
|
||||
//for rows5.Next() {
|
||||
//err = rows5.Scan(&KtoZabral, &KosztBiletu)
|
||||
//checkErr3(err)
|
||||
if KtoZabral == User {
|
||||
t, _ := template.ParseFiles("platnosci.gtpl")
|
||||
d := struct {
|
||||
IDbiletuView int
|
||||
KtoZabralView string
|
||||
DataCzasView string
|
||||
KosztBiletuView int
|
||||
UserView string
|
||||
KosztBiletuViewSuma int
|
||||
}{
|
||||
IDbiletuView: IDbiletu,
|
||||
KtoZabralView: KtoZabral,
|
||||
DataCzasView: DataCzas,
|
||||
KosztBiletuView: KosztBiletu}
|
||||
UserView: User,
|
||||
KosztBiletuViewSuma: }
|
||||
t.ExecuteTemplate(w, "platnosci.gtpl", d)
|
||||
//break
|
||||
}
|
||||
//----------------------------------
|
||||
//}
|
||||
*/
|
||||
for rows5.Next() {
|
||||
rows5.Scan(&KtoZabral, &KosztBiletu)
|
||||
fmt.Printf("%v %v\n", KtoZabral, KosztBiletu)
|
||||
}
|
||||
rows4.Close()
|
||||
rows5.Close()
|
||||
db.Close()
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
//Bazy danych SQlite
|
||||
//Obsługa błędów
|
||||
//***************************************************************************
|
||||
|
||||
func checkErr(err error) {
|
||||
@ -250,6 +308,16 @@ func checkErr(err error) {
|
||||
fmt.Println("Błąd")
|
||||
}
|
||||
}
|
||||
func checkErr2(err error) {
|
||||
if err != nil {
|
||||
fmt.Println("Błąd dwa")
|
||||
}
|
||||
}
|
||||
func checkErr3(err error) {
|
||||
if err != nil {
|
||||
fmt.Println("Błąd trzy")
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
//funkcja główna
|
||||
@ -260,6 +328,7 @@ func main() {
|
||||
http.HandleFunc("/panel", panel)
|
||||
http.HandleFunc("/historiaPosilkow", historiaPosilkow)
|
||||
http.HandleFunc("/platnosci", platnosci)
|
||||
http.HandleFunc("/wylogowano", wylogowano)
|
||||
|
||||
err := http.ListenAndServe(":9197", nil)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user