Update main.go
This commit is contained in:
parent
ae6899714d
commit
90076633df
98
main.go
98
main.go
@ -1,20 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
//"container/list"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
//"sync"
|
||||
//"time"
|
||||
//"net/url"
|
||||
|
||||
//"time"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var (
|
||||
//sesja
|
||||
key = []byte("1010101010101")
|
||||
store = sessions.NewCookieStore(key)
|
||||
|
||||
//do rejestracji biletu
|
||||
KosztBiletuSUMA int
|
||||
|
||||
//zmiana pinu, hasła i blokada karty
|
||||
@ -54,19 +61,23 @@ var (
|
||||
//funkcje sterujące
|
||||
//***************************************************************************
|
||||
|
||||
//#############################################################################
|
||||
func sesja(w http.ResponseWriter, r *http.Request) {
|
||||
t, _ := template.ParseFiles("sesja.gtpl")
|
||||
t.Execute(w, nil)
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
|
||||
//fmt.Println(localHostDB)
|
||||
t, _ := template.ParseFiles("StronaGlowna.gohtml")
|
||||
t.Execute(w, nil)
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func panel(w http.ResponseWriter, r *http.Request) {
|
||||
for _, cookie := range r.Cookies() {
|
||||
fmt.Fprint(w, cookie.Name)
|
||||
}
|
||||
|
||||
if User == "lost" {
|
||||
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||
} else {
|
||||
fmt.Println("method:", r.Method)
|
||||
t, _ := template.ParseFiles("panel.gtpl")
|
||||
d := struct {
|
||||
@ -75,6 +86,7 @@ func panel(w http.ResponseWriter, r *http.Request) {
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "panel.gtpl", d)
|
||||
}
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
@ -91,10 +103,40 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
dzialanie, err := up.RowsAffected()
|
||||
checkErr(err)
|
||||
fmt.Println(dzialanie)
|
||||
|
||||
db.Close()
|
||||
}
|
||||
//--------------------------------------------------
|
||||
//sesja----
|
||||
session, err := store.Get(r, "sesja1")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
session.Values[User] = false
|
||||
session.Save(r, w)
|
||||
//---------
|
||||
//ustaw wartości na null
|
||||
KosztBiletuSUMA = 0
|
||||
pinFROMsite = 0
|
||||
RFIDblockORno = "lost"
|
||||
hasloFROMsite = "lost"
|
||||
loginFROMsite = "lost"
|
||||
passwordFROMsite = "lost"
|
||||
IDusers = 0
|
||||
User = "lost"
|
||||
Password = "lost"
|
||||
PIN = 0
|
||||
RFID = 0
|
||||
Login = "lost"
|
||||
IDbiletu = 0
|
||||
KtoZabralID = 0
|
||||
DataCzas = "lost"
|
||||
KosztBiletu = 0
|
||||
CzyZaplacony = "lost"
|
||||
IDdania = 0
|
||||
NazwaDania = "lost"
|
||||
KosztDania = 0
|
||||
User = "lost"
|
||||
|
||||
t, _ := template.ParseFiles("wylogowano.gtpl")
|
||||
type user struct {
|
||||
@ -103,6 +145,7 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
||||
u := user{
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "wylogowano.gtpl", u)
|
||||
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
@ -122,6 +165,15 @@ func login(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
if Login == loginFROMsite {
|
||||
if Password == passwordFROMsite {
|
||||
//sesja start-----
|
||||
session, err := store.Get(r, "sesja1")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
session.Values[User] = true
|
||||
session.Save(r, w)
|
||||
//----------------
|
||||
http.Redirect(w, r, "http://localhost:9197/panel", http.StatusSeeOther)
|
||||
panel(w, r)
|
||||
break
|
||||
@ -161,6 +213,9 @@ func login(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
//#############################################################################
|
||||
func menuDan(w http.ResponseWriter, r *http.Request) {
|
||||
if User == "lost" {
|
||||
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||
} else {
|
||||
t, _ := template.ParseFiles("menuDanNaglowek.gtpl")
|
||||
d := struct {
|
||||
UserView string
|
||||
@ -191,9 +246,13 @@ func menuDan(w http.ResponseWriter, r *http.Request) {
|
||||
rows2.Close()
|
||||
db.Close()
|
||||
}
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||
if User == "lost" {
|
||||
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||
} else {
|
||||
t, _ := template.ParseFiles("historiaPosilkowNaglowek.gtpl")
|
||||
d := struct {
|
||||
UserView string
|
||||
@ -230,10 +289,13 @@ func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||
rows3.Close()
|
||||
db.Close()
|
||||
}
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func platnosci(w http.ResponseWriter, r *http.Request) {
|
||||
//fmt.Fprint(w, User)
|
||||
if User == "lost" {
|
||||
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||
} else {
|
||||
|
||||
//bilety ----------------------------------
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
@ -265,9 +327,13 @@ func platnosci(w http.ResponseWriter, r *http.Request) {
|
||||
rows5.Close()
|
||||
db.Close()
|
||||
}
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func placeOnline(w http.ResponseWriter, r *http.Request) {
|
||||
if User == "lost" {
|
||||
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||
} else {
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
rows5, err := db.Query("SELECT * FROM bilety WHERE KtoZabralID=?", IDusers)
|
||||
@ -294,9 +360,13 @@ func placeOnline(w http.ResponseWriter, r *http.Request) {
|
||||
rows5.Close()
|
||||
db.Close()
|
||||
}
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func zaplacono(w http.ResponseWriter, r *http.Request) {
|
||||
if User == "lost" {
|
||||
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||
} else {
|
||||
|
||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||
checkErr(err)
|
||||
@ -324,9 +394,13 @@ func zaplacono(w http.ResponseWriter, r *http.Request) {
|
||||
t.ExecuteTemplate(w, "zaplacono.gtpl", z)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func zmianaPINU(w http.ResponseWriter, r *http.Request) {
|
||||
if User == "lost" {
|
||||
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||
} else {
|
||||
pinFROMsite := r.FormValue("pinFROMsite")
|
||||
RFIDblockORno := r.FormValue("RFID")
|
||||
|
||||
@ -390,9 +464,13 @@ func zmianaPINU(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
func zmianaHasla(w http.ResponseWriter, r *http.Request) {
|
||||
if User == "lost" {
|
||||
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||
} else {
|
||||
//templatka przekierowuje do funkcji wylogowano
|
||||
t, _ := template.ParseFiles("zmianaHasla.gtpl")
|
||||
type zmhaslo struct {
|
||||
@ -402,6 +480,7 @@ func zmianaHasla(w http.ResponseWriter, r *http.Request) {
|
||||
UserView: User}
|
||||
t.ExecuteTemplate(w, "zmianaHasla.gtpl", wykonaj)
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
//Obsługa błędów
|
||||
@ -438,6 +517,7 @@ func main() {
|
||||
http.HandleFunc("/menuDan", menuDan)
|
||||
http.HandleFunc("/zmianaPINU", zmianaPINU)
|
||||
http.HandleFunc("/zmianaHasla", zmianaHasla)
|
||||
http.HandleFunc("/sesja", sesja)
|
||||
|
||||
err := http.ListenAndServe(":9197", nil)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user