Update main.go

This commit is contained in:
s441433 2019-01-02 16:32:13 +01:00
parent cf1b56b21d
commit 711c328202

131
main.go
View File

@ -17,7 +17,6 @@ import (
//logowanie ------------ //logowanie ------------
var loginFROMsite string var loginFROMsite string
var passwordFROMsite string var passwordFROMsite string
var UserView string
//users --------------- //users ---------------
var IDusers int var IDusers int
@ -34,6 +33,7 @@ var IDbiletu int
var KtoZabral string var KtoZabral string
var DataCzas string var DataCzas string
var KosztBiletu int var KosztBiletu int
var CzyZaplacony bool
//dania --------------- //dania ---------------
var IDdania int var IDdania int
@ -81,6 +81,9 @@ func panel(w http.ResponseWriter, r *http.Request) {
rows2.Close() rows2.Close()
db.Close() db.Close()
*/ */
for _, cookie := range r.Cookies() {
fmt.Fprint(w, cookie.Name)
}
fmt.Println("method:", r.Method) fmt.Println("method:", r.Method)
t, _ := template.ParseFiles("panel.gtpl") t, _ := template.ParseFiles("panel.gtpl")
@ -91,8 +94,60 @@ func panel(w http.ResponseWriter, r *http.Request) {
t.ExecuteTemplate(w, "panel.gtpl", d) 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) { func login(w http.ResponseWriter, r *http.Request) {
//cookies start===================================================================
type Cookie struct {
Login string
Password string
}
//cookies end===================================================================
loginFROMsite := r.FormValue("loginFROMsite") loginFROMsite := r.FormValue("loginFROMsite")
passwordFROMsite := r.FormValue("passwordFROMsite") passwordFROMsite := r.FormValue("passwordFROMsite")
//zaloguj := "Zalogowano!" //zaloguj := "Zalogowano!"
@ -182,20 +237,22 @@ func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
rows3, err := db.Query("SELECT * FROM bilety") rows3, err := db.Query("SELECT * FROM bilety")
checkErr(err) checkErr(err)
for rows3.Next() { for rows3.Next() {
err = rows3.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu) err = rows3.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu, &CzyZaplacony)
checkErr(err) checkErr(err)
if KtoZabral == User { if KtoZabral == User {
t, _ := template.ParseFiles("historiaPosilkow.gtpl") t, _ := template.ParseFiles("historiaPosilkow.gtpl")
d := struct { d := struct {
IDbiletuView int IDbiletuView int
KtoZabralView string KtoZabralView string
DataCzasView string DataCzasView string
KosztBiletuView int KosztBiletuView int
CzyZaplaconyView bool
}{ }{
IDbiletuView: IDbiletu, IDbiletuView: IDbiletu,
KtoZabralView: KtoZabral, KtoZabralView: KtoZabral,
DataCzasView: DataCzas, DataCzasView: DataCzas,
KosztBiletuView: KosztBiletu} KosztBiletuView: KosztBiletu,
CzyZaplaconyView: CzyZaplacony}
t.ExecuteTemplate(w, "historiaPosilkow.gtpl", d) 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) { func platnosci(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("platnosci.gtpl") //fmt.Fprint(w, User)
d := struct {
UserView string
}{
UserView: User}
t.ExecuteTemplate(w, "platnosci.gtpl", d)
//bilety ---------------------------------- //bilety ----------------------------------
db, err := sql.Open("sqlite3", "stolowkaZPM.db") db, err := sql.Open("sqlite3", "stolowkaZPM.db")
checkErr(err) checkErr(err)
rows4, err := db.Query("SELECT * FROM bilety") rows5, err := db.Query("SELECT SUM(KosztBiletu)FROM bilety WHERE KtoZabral=?", User)
checkErr(err) if err != nil {
for rows4.Next() { fmt.Println(err)
err = rows4.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu) // os.Exit(1)
checkErr(err) }
/*
//for rows5.Next() {
//err = rows5.Scan(&KtoZabral, &KosztBiletu)
//checkErr3(err)
if KtoZabral == User { if KtoZabral == User {
t, _ := template.ParseFiles("platnosci.gtpl") t, _ := template.ParseFiles("platnosci.gtpl")
d := struct { d := struct {
IDbiletuView int UserView string
KtoZabralView string KosztBiletuViewSuma int
DataCzasView string
KosztBiletuView int
}{ }{
IDbiletuView: IDbiletu, UserView: User,
KtoZabralView: KtoZabral, KosztBiletuViewSuma: }
DataCzasView: DataCzas,
KosztBiletuView: KosztBiletu}
t.ExecuteTemplate(w, "platnosci.gtpl", d) 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() db.Close()
} }
//*************************************************************************** //***************************************************************************
//Bazy danych SQlite //Obsługa błędów
//*************************************************************************** //***************************************************************************
func checkErr(err error) { func checkErr(err error) {
@ -250,6 +308,16 @@ func checkErr(err error) {
fmt.Println("Błąd") 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 //funkcja główna
@ -260,6 +328,7 @@ func main() {
http.HandleFunc("/panel", panel) http.HandleFunc("/panel", panel)
http.HandleFunc("/historiaPosilkow", historiaPosilkow) http.HandleFunc("/historiaPosilkow", historiaPosilkow)
http.HandleFunc("/platnosci", platnosci) http.HandleFunc("/platnosci", platnosci)
http.HandleFunc("/wylogowano", wylogowano)
err := http.ListenAndServe(":9197", nil) err := http.ListenAndServe(":9197", nil)
if err != nil { if err != nil {