Update main.go
This commit is contained in:
parent
8bd8cadd52
commit
f6b2b904cc
180
main.go
180
main.go
@ -17,6 +17,11 @@ import (
|
||||
var (
|
||||
KosztBiletuSUMA int
|
||||
|
||||
//zmiana pinu, hasła i blokada karty
|
||||
pinFROMsite int
|
||||
RFIDblockORno string
|
||||
hasloFROMsite string
|
||||
|
||||
//logowanie ------------
|
||||
loginFROMsite string
|
||||
passwordFROMsite string
|
||||
@ -29,14 +34,13 @@ var (
|
||||
RFID int
|
||||
Login string
|
||||
Blokada bool
|
||||
Koszt int
|
||||
|
||||
//bilety ---------------
|
||||
IDbiletu int
|
||||
KtoZabral string
|
||||
DataCzas string
|
||||
KosztBiletu int
|
||||
CzyZaplacony bool
|
||||
CzyZaplacony string
|
||||
|
||||
//dania ---------------
|
||||
IDdania int
|
||||
@ -59,36 +63,6 @@ func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
//#############################################################################
|
||||
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()
|
||||
*/
|
||||
for _, cookie := range r.Cookies() {
|
||||
fmt.Fprint(w, cookie.Name)
|
||||
}
|
||||
@ -104,9 +78,34 @@ func panel(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
//#############################################################################
|
||||
func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
//--------------------------------------------------
|
||||
hasloFROMsite := r.FormValue("hasloFROMsite")
|
||||
if hasloFROMsite != "" {
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
|
||||
akt, err := db.Prepare("UPDATE users SET Password=? WHERE IDusers=?")
|
||||
checkErr(err)
|
||||
up, err := akt.Exec(hasloFROMsite, IDusers)
|
||||
checkErr(err)
|
||||
dzialanie, err := up.RowsAffected()
|
||||
checkErr(err)
|
||||
fmt.Println(dzialanie)
|
||||
|
||||
db.Close()
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
t, _ := template.ParseFiles("wylogowano.gtpl")
|
||||
type user struct {
|
||||
UserView string
|
||||
}
|
||||
u := user{
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "wylogowano.gtpl", u)
|
||||
}
|
||||
|
||||
/*
|
||||
d := struct {
|
||||
loginFROMsiteView string
|
||||
passwordFROMsiteView string
|
||||
@ -143,9 +142,7 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
IDdaniaView: 0,
|
||||
NazwaDaniaView: "",
|
||||
KosztDaniaView: 0}
|
||||
|
||||
t.ExecuteTemplate(w, "wylogowano.gtpl", d)
|
||||
}
|
||||
*/
|
||||
|
||||
//#############################################################################
|
||||
func login(w http.ResponseWriter, r *http.Request) {
|
||||
@ -159,13 +156,8 @@ func login(w http.ResponseWriter, r *http.Request) {
|
||||
checkErr(err)
|
||||
|
||||
for rows0.Next() {
|
||||
err = rows0.Scan(&IDusers, &User, &Password, &PIN, &RFID, &Login, &Blokada, &Koszt)
|
||||
err = rows0.Scan(&IDusers, &User, &Password, &PIN, &RFID, &Login, &Blokada)
|
||||
checkErr(err)
|
||||
//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 Login == loginFROMsite {
|
||||
if Password == passwordFROMsite {
|
||||
@ -263,7 +255,7 @@ func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||
KtoZabralView string
|
||||
DataCzasView string
|
||||
KosztBiletuView int
|
||||
CzyZaplaconyView bool
|
||||
CzyZaplaconyView string
|
||||
}{
|
||||
IDbiletuView: IDbiletu,
|
||||
KtoZabralView: KtoZabral,
|
||||
@ -292,11 +284,12 @@ func platnosci(w http.ResponseWriter, r *http.Request) {
|
||||
err = rows5.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
||||
checkErr3(err)
|
||||
//if KtoZabral == User {
|
||||
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
||||
//}
|
||||
if CzyZaplacony == "nie" {
|
||||
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
||||
}
|
||||
//----------------------------------
|
||||
}
|
||||
fmt.Println(KosztBiletuSUMA)
|
||||
//fmt.Println(KosztBiletuSUMA)
|
||||
t, _ := template.ParseFiles("platnosci.gtpl")
|
||||
checkErr(err)
|
||||
type zaplac struct {
|
||||
@ -312,6 +305,100 @@ func platnosci(w http.ResponseWriter, r *http.Request) {
|
||||
db.Close()
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func placeOnline(w http.ResponseWriter, r *http.Request) {
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
rows5, err := db.Query("SELECT * FROM bilety WHERE KtoZabral=?", User)
|
||||
checkErr(err)
|
||||
KosztBiletuSUMA = 0
|
||||
for rows5.Next() {
|
||||
err = rows5.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
||||
checkErr3(err)
|
||||
if CzyZaplacony == "nie" {
|
||||
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
||||
}
|
||||
}
|
||||
t, _ := template.ParseFiles("placeOnline.gtpl")
|
||||
checkErr(err)
|
||||
type zaplac struct {
|
||||
UserView string
|
||||
Zaplac int
|
||||
}
|
||||
z := zaplac{
|
||||
UserView: User,
|
||||
Zaplac: KosztBiletuSUMA}
|
||||
|
||||
t.ExecuteTemplate(w, "placeOnline.gtpl", z)
|
||||
rows5.Close()
|
||||
db.Close()
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func zmianaPINU(w http.ResponseWriter, r *http.Request) {
|
||||
pinFROMsite := r.FormValue("pinFROMsite")
|
||||
RFIDblockORno := r.FormValue("RFID")
|
||||
|
||||
t, _ := template.ParseFiles("zmianaPINU.gtpl")
|
||||
type pinIblokada struct {
|
||||
UserView string
|
||||
}
|
||||
wykonaj := pinIblokada{
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "zmianaPINU.gtpl", wykonaj)
|
||||
|
||||
if pinFROMsite != "" {
|
||||
fmt.Fprintln(w, "*** --- Pin został POMYŚLNIE ZMIENIONY! --- *** \n")
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
|
||||
akt, err := db.Prepare("UPDATE users SET PIN=? WHERE IDusers=?")
|
||||
checkErr(err)
|
||||
up, err := akt.Exec(pinFROMsite, IDusers)
|
||||
checkErr(err)
|
||||
dzialanie, err := up.RowsAffected()
|
||||
checkErr(err)
|
||||
fmt.Println(dzialanie)
|
||||
|
||||
rows0, err := db.Query("SELECT * FROM users")
|
||||
checkErr(err)
|
||||
|
||||
for rows0.Next() {
|
||||
err = rows0.Scan(&IDusers, &User, &Password, &PIN, &RFID, &Login, &Blokada)
|
||||
checkErr(err)
|
||||
fmt.Printf("%d. %s, %s, %d, %d, %s, %v \n", IDusers, User, Password, PIN, RFID, Login, Blokada)
|
||||
|
||||
}
|
||||
|
||||
rows0.Close()
|
||||
db.Close()
|
||||
|
||||
}
|
||||
if RFIDblockORno == "RFIDblock" {
|
||||
//Blokada := true
|
||||
fmt.Fprintln(w, "*** --- Karta RFID została ZABLOKOWANA! --- *** \n")
|
||||
|
||||
} else {
|
||||
if RFIDblockORno == "RFIDunlock" {
|
||||
//Blokada := true
|
||||
fmt.Fprintln(w, "*** --- Karta RFID została ODBLOKOWANA! --- *** \n")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func zmianaHasla(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
t, _ := template.ParseFiles("zmianaHasla.gtpl")
|
||||
type zmhaslo struct {
|
||||
UserView string
|
||||
}
|
||||
wykonaj := zmhaslo{
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "zmianaHasla.gtpl", wykonaj)
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
//Obsługa błędów
|
||||
//***************************************************************************
|
||||
@ -341,8 +428,11 @@ func main() {
|
||||
http.HandleFunc("/panel", panel)
|
||||
http.HandleFunc("/historiaPosilkow", historiaPosilkow)
|
||||
http.HandleFunc("/platnosci", platnosci)
|
||||
http.HandleFunc("/platnosci/placeOnline", placeOnline)
|
||||
http.HandleFunc("/wylogowano", wylogowano)
|
||||
http.HandleFunc("/menuDan", menuDan)
|
||||
http.HandleFunc("/zmianaPINU", zmianaPINU)
|
||||
http.HandleFunc("/zmianaHasla", zmianaHasla)
|
||||
|
||||
err := http.ListenAndServe(":9197", nil)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user