Update main.go
This commit is contained in:
parent
8bd8cadd52
commit
f6b2b904cc
180
main.go
180
main.go
@ -17,6 +17,11 @@ import (
|
|||||||
var (
|
var (
|
||||||
KosztBiletuSUMA int
|
KosztBiletuSUMA int
|
||||||
|
|
||||||
|
//zmiana pinu, hasła i blokada karty
|
||||||
|
pinFROMsite int
|
||||||
|
RFIDblockORno string
|
||||||
|
hasloFROMsite string
|
||||||
|
|
||||||
//logowanie ------------
|
//logowanie ------------
|
||||||
loginFROMsite string
|
loginFROMsite string
|
||||||
passwordFROMsite string
|
passwordFROMsite string
|
||||||
@ -29,14 +34,13 @@ var (
|
|||||||
RFID int
|
RFID int
|
||||||
Login string
|
Login string
|
||||||
Blokada bool
|
Blokada bool
|
||||||
Koszt int
|
|
||||||
|
|
||||||
//bilety ---------------
|
//bilety ---------------
|
||||||
IDbiletu int
|
IDbiletu int
|
||||||
KtoZabral string
|
KtoZabral string
|
||||||
DataCzas string
|
DataCzas string
|
||||||
KosztBiletu int
|
KosztBiletu int
|
||||||
CzyZaplacony bool
|
CzyZaplacony string
|
||||||
|
|
||||||
//dania ---------------
|
//dania ---------------
|
||||||
IDdania int
|
IDdania int
|
||||||
@ -59,36 +63,6 @@ func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func panel(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() {
|
for _, cookie := range r.Cookies() {
|
||||||
fmt.Fprint(w, cookie.Name)
|
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) {
|
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")
|
t, _ := template.ParseFiles("wylogowano.gtpl")
|
||||||
|
type user struct {
|
||||||
|
UserView string
|
||||||
|
}
|
||||||
|
u := user{
|
||||||
|
UserView: User}
|
||||||
|
t.ExecuteTemplate(w, "wylogowano.gtpl", u)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
d := struct {
|
d := struct {
|
||||||
loginFROMsiteView string
|
loginFROMsiteView string
|
||||||
passwordFROMsiteView string
|
passwordFROMsiteView string
|
||||||
@ -143,9 +142,7 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
|||||||
IDdaniaView: 0,
|
IDdaniaView: 0,
|
||||||
NazwaDaniaView: "",
|
NazwaDaniaView: "",
|
||||||
KosztDaniaView: 0}
|
KosztDaniaView: 0}
|
||||||
|
*/
|
||||||
t.ExecuteTemplate(w, "wylogowano.gtpl", d)
|
|
||||||
}
|
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func login(w http.ResponseWriter, r *http.Request) {
|
func login(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -159,13 +156,8 @@ func login(w http.ResponseWriter, r *http.Request) {
|
|||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
for rows0.Next() {
|
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)
|
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 r.Method == "POST" {
|
||||||
if Login == loginFROMsite {
|
if Login == loginFROMsite {
|
||||||
if Password == passwordFROMsite {
|
if Password == passwordFROMsite {
|
||||||
@ -263,7 +255,7 @@ func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
|||||||
KtoZabralView string
|
KtoZabralView string
|
||||||
DataCzasView string
|
DataCzasView string
|
||||||
KosztBiletuView int
|
KosztBiletuView int
|
||||||
CzyZaplaconyView bool
|
CzyZaplaconyView string
|
||||||
}{
|
}{
|
||||||
IDbiletuView: IDbiletu,
|
IDbiletuView: IDbiletu,
|
||||||
KtoZabralView: KtoZabral,
|
KtoZabralView: KtoZabral,
|
||||||
@ -292,11 +284,12 @@ func platnosci(w http.ResponseWriter, r *http.Request) {
|
|||||||
err = rows5.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
err = rows5.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
||||||
checkErr3(err)
|
checkErr3(err)
|
||||||
//if KtoZabral == User {
|
//if KtoZabral == User {
|
||||||
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
if CzyZaplacony == "nie" {
|
||||||
//}
|
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
||||||
|
}
|
||||||
//----------------------------------
|
//----------------------------------
|
||||||
}
|
}
|
||||||
fmt.Println(KosztBiletuSUMA)
|
//fmt.Println(KosztBiletuSUMA)
|
||||||
t, _ := template.ParseFiles("platnosci.gtpl")
|
t, _ := template.ParseFiles("platnosci.gtpl")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
type zaplac struct {
|
type zaplac struct {
|
||||||
@ -312,6 +305,100 @@ func platnosci(w http.ResponseWriter, r *http.Request) {
|
|||||||
db.Close()
|
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
|
//Obsługa błędów
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
@ -341,8 +428,11 @@ 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("/platnosci/placeOnline", placeOnline)
|
||||||
http.HandleFunc("/wylogowano", wylogowano)
|
http.HandleFunc("/wylogowano", wylogowano)
|
||||||
http.HandleFunc("/menuDan", menuDan)
|
http.HandleFunc("/menuDan", menuDan)
|
||||||
|
http.HandleFunc("/zmianaPINU", zmianaPINU)
|
||||||
|
http.HandleFunc("/zmianaHasla", zmianaHasla)
|
||||||
|
|
||||||
err := http.ListenAndServe(":9197", nil)
|
err := http.ListenAndServe(":9197", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user