Update main.go
This commit is contained in:
parent
ae6899714d
commit
90076633df
474
main.go
474
main.go
@ -1,20 +1,27 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
//"container/list"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
//"sync"
|
||||||
|
//"time"
|
||||||
//"net/url"
|
//"net/url"
|
||||||
|
|
||||||
//"time"
|
"github.com/gorilla/sessions"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
//sesja
|
||||||
|
key = []byte("1010101010101")
|
||||||
|
store = sessions.NewCookieStore(key)
|
||||||
|
|
||||||
|
//do rejestracji biletu
|
||||||
KosztBiletuSUMA int
|
KosztBiletuSUMA int
|
||||||
|
|
||||||
//zmiana pinu, hasła i blokada karty
|
//zmiana pinu, hasła i blokada karty
|
||||||
@ -54,26 +61,31 @@ var (
|
|||||||
//funkcje sterujące
|
//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) {
|
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
|
||||||
//fmt.Println(localHostDB)
|
|
||||||
t, _ := template.ParseFiles("StronaGlowna.gohtml")
|
t, _ := template.ParseFiles("StronaGlowna.gohtml")
|
||||||
t.Execute(w, nil)
|
t.Execute(w, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func panel(w http.ResponseWriter, r *http.Request) {
|
func panel(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, cookie := range r.Cookies() {
|
if User == "lost" {
|
||||||
fmt.Fprint(w, cookie.Name)
|
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||||
|
} else {
|
||||||
|
fmt.Println("method:", r.Method)
|
||||||
|
t, _ := template.ParseFiles("panel.gtpl")
|
||||||
|
d := struct {
|
||||||
|
UserView string
|
||||||
|
}{
|
||||||
|
UserView: User}
|
||||||
|
t.ExecuteTemplate(w, "panel.gtpl", d)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("method:", r.Method)
|
|
||||||
t, _ := template.ParseFiles("panel.gtpl")
|
|
||||||
d := struct {
|
|
||||||
UserView string
|
|
||||||
}{
|
|
||||||
UserView: User}
|
|
||||||
t.ExecuteTemplate(w, "panel.gtpl", d)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
@ -91,10 +103,40 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
|||||||
dzialanie, err := up.RowsAffected()
|
dzialanie, err := up.RowsAffected()
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
fmt.Println(dzialanie)
|
fmt.Println(dzialanie)
|
||||||
|
|
||||||
db.Close()
|
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")
|
t, _ := template.ParseFiles("wylogowano.gtpl")
|
||||||
type user struct {
|
type user struct {
|
||||||
@ -103,6 +145,7 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
|||||||
u := user{
|
u := user{
|
||||||
UserView: User}
|
UserView: User}
|
||||||
t.ExecuteTemplate(w, "wylogowano.gtpl", u)
|
t.ExecuteTemplate(w, "wylogowano.gtpl", u)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
@ -122,6 +165,15 @@ func login(w http.ResponseWriter, r *http.Request) {
|
|||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
if Login == loginFROMsite {
|
if Login == loginFROMsite {
|
||||||
if Password == passwordFROMsite {
|
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)
|
http.Redirect(w, r, "http://localhost:9197/panel", http.StatusSeeOther)
|
||||||
panel(w, r)
|
panel(w, r)
|
||||||
break
|
break
|
||||||
@ -161,225 +213,213 @@ func login(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func menuDan(w http.ResponseWriter, r *http.Request) {
|
func menuDan(w http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.ParseFiles("menuDanNaglowek.gtpl")
|
if User == "lost" {
|
||||||
d := struct {
|
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||||
UserView string
|
} else {
|
||||||
}{
|
t, _ := template.ParseFiles("menuDanNaglowek.gtpl")
|
||||||
UserView: User}
|
|
||||||
t.ExecuteTemplate(w, "menuDanNaglowek.gtpl", d)
|
|
||||||
//dania ----------------------------------
|
|
||||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
|
||||||
checkErr2(err)
|
|
||||||
rows2, err := db.Query("SELECT * FROM dania")
|
|
||||||
checkErr(err)
|
|
||||||
for rows2.Next() {
|
|
||||||
err = rows2.Scan(&IDdania, &NazwaDania, &KosztDania)
|
|
||||||
checkErr3(err)
|
|
||||||
//fmt.Printf("%d. %s, %d \n", IDdania, NazwaDania, KosztDania)
|
|
||||||
t, _ := template.ParseFiles("menuDan.gtpl")
|
|
||||||
d := struct {
|
d := struct {
|
||||||
IDdaniaView int
|
UserView string
|
||||||
NazwaDaniaView string
|
|
||||||
KosztDaniaView int
|
|
||||||
}{
|
}{
|
||||||
IDdaniaView: IDdania,
|
UserView: User}
|
||||||
NazwaDaniaView: NazwaDania,
|
t.ExecuteTemplate(w, "menuDanNaglowek.gtpl", d)
|
||||||
KosztDaniaView: KosztDania}
|
//dania ----------------------------------
|
||||||
t.ExecuteTemplate(w, "menuDan.gtpl", d)
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
|
checkErr2(err)
|
||||||
|
rows2, err := db.Query("SELECT * FROM dania")
|
||||||
|
checkErr(err)
|
||||||
|
for rows2.Next() {
|
||||||
|
err = rows2.Scan(&IDdania, &NazwaDania, &KosztDania)
|
||||||
|
checkErr3(err)
|
||||||
|
//fmt.Printf("%d. %s, %d \n", IDdania, NazwaDania, KosztDania)
|
||||||
|
t, _ := template.ParseFiles("menuDan.gtpl")
|
||||||
|
d := struct {
|
||||||
|
IDdaniaView int
|
||||||
|
NazwaDaniaView string
|
||||||
|
KosztDaniaView int
|
||||||
|
}{
|
||||||
|
IDdaniaView: IDdania,
|
||||||
|
NazwaDaniaView: NazwaDania,
|
||||||
|
KosztDaniaView: KosztDania}
|
||||||
|
t.ExecuteTemplate(w, "menuDan.gtpl", d)
|
||||||
|
}
|
||||||
|
//----------------------------------
|
||||||
|
rows2.Close()
|
||||||
|
db.Close()
|
||||||
}
|
}
|
||||||
//----------------------------------
|
|
||||||
rows2.Close()
|
|
||||||
db.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.ParseFiles("historiaPosilkowNaglowek.gtpl")
|
if User == "lost" {
|
||||||
d := struct {
|
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||||
UserView string
|
} else {
|
||||||
}{
|
t, _ := template.ParseFiles("historiaPosilkowNaglowek.gtpl")
|
||||||
UserView: User}
|
d := struct {
|
||||||
t.ExecuteTemplate(w, "historiaPosilkowNaglowek.gtpl", d)
|
UserView string
|
||||||
|
}{
|
||||||
|
UserView: User}
|
||||||
|
t.ExecuteTemplate(w, "historiaPosilkowNaglowek.gtpl", d)
|
||||||
|
|
||||||
//bilety ----------------------------------
|
//bilety ----------------------------------
|
||||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
checkErr(err)
|
|
||||||
rows3, err := db.Query("SELECT * FROM bilety")
|
|
||||||
checkErr(err)
|
|
||||||
for rows3.Next() {
|
|
||||||
err = rows3.Scan(&IDbiletu, &KtoZabralID, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
if KtoZabralID == IDusers {
|
rows3, err := db.Query("SELECT * FROM bilety")
|
||||||
t, _ := template.ParseFiles("historiaPosilkow.gtpl")
|
checkErr(err)
|
||||||
d := struct {
|
for rows3.Next() {
|
||||||
IDbiletuView int
|
err = rows3.Scan(&IDbiletu, &KtoZabralID, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
||||||
KtoZabralView int
|
checkErr(err)
|
||||||
DataCzasView string
|
if KtoZabralID == IDusers {
|
||||||
KosztBiletuView int
|
t, _ := template.ParseFiles("historiaPosilkow.gtpl")
|
||||||
CzyZaplaconyView string
|
d := struct {
|
||||||
}{
|
IDbiletuView int
|
||||||
IDbiletuView: IDbiletu,
|
KtoZabralView int
|
||||||
KtoZabralView: KtoZabralID,
|
DataCzasView string
|
||||||
DataCzasView: DataCzas,
|
KosztBiletuView int
|
||||||
KosztBiletuView: KosztBiletu,
|
CzyZaplaconyView string
|
||||||
CzyZaplaconyView: CzyZaplacony}
|
}{
|
||||||
t.ExecuteTemplate(w, "historiaPosilkow.gtpl", d)
|
IDbiletuView: IDbiletu,
|
||||||
|
KtoZabralView: KtoZabralID,
|
||||||
|
DataCzasView: DataCzas,
|
||||||
|
KosztBiletuView: KosztBiletu,
|
||||||
|
CzyZaplaconyView: CzyZaplacony}
|
||||||
|
t.ExecuteTemplate(w, "historiaPosilkow.gtpl", d)
|
||||||
|
}
|
||||||
|
//----------------------------------
|
||||||
}
|
}
|
||||||
//----------------------------------
|
rows3.Close()
|
||||||
|
db.Close()
|
||||||
}
|
}
|
||||||
rows3.Close()
|
|
||||||
db.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func platnosci(w http.ResponseWriter, r *http.Request) {
|
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 ----------------------------------
|
//bilety ----------------------------------
|
||||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
rows5, err := db.Query("SELECT * FROM bilety WHERE KtoZabralID=?", IDusers)
|
rows5, err := db.Query("SELECT * FROM bilety WHERE KtoZabralID=?", IDusers)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
KosztBiletuSUMA = 0
|
KosztBiletuSUMA = 0
|
||||||
for rows5.Next() {
|
for rows5.Next() {
|
||||||
err = rows5.Scan(&IDbiletu, &KtoZabralID, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
err = rows5.Scan(&IDbiletu, &KtoZabralID, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
||||||
checkErr3(err)
|
checkErr3(err)
|
||||||
//if KtoZabralID == User {
|
//if KtoZabralID == User {
|
||||||
if CzyZaplacony == "nie" {
|
if CzyZaplacony == "nie" {
|
||||||
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
||||||
|
}
|
||||||
|
//----------------------------------
|
||||||
}
|
}
|
||||||
//----------------------------------
|
//fmt.Println(KosztBiletuSUMA)
|
||||||
}
|
t, _ := template.ParseFiles("platnosci.gtpl")
|
||||||
//fmt.Println(KosztBiletuSUMA)
|
checkErr(err)
|
||||||
t, _ := template.ParseFiles("platnosci.gtpl")
|
type zaplac struct {
|
||||||
checkErr(err)
|
UserView string
|
||||||
type zaplac struct {
|
Zaplac int
|
||||||
UserView string
|
}
|
||||||
Zaplac int
|
z := zaplac{
|
||||||
}
|
UserView: User,
|
||||||
z := zaplac{
|
Zaplac: KosztBiletuSUMA}
|
||||||
UserView: User,
|
|
||||||
Zaplac: KosztBiletuSUMA}
|
|
||||||
|
|
||||||
t.ExecuteTemplate(w, "platnosci.gtpl", z)
|
t.ExecuteTemplate(w, "platnosci.gtpl", z)
|
||||||
rows5.Close()
|
rows5.Close()
|
||||||
db.Close()
|
db.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func placeOnline(w http.ResponseWriter, r *http.Request) {
|
func placeOnline(w http.ResponseWriter, r *http.Request) {
|
||||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
if User == "lost" {
|
||||||
checkErr(err)
|
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||||
rows5, err := db.Query("SELECT * FROM bilety WHERE KtoZabralID=?", IDusers)
|
} else {
|
||||||
checkErr(err)
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
KosztBiletuSUMA = 0
|
checkErr(err)
|
||||||
for rows5.Next() {
|
rows5, err := db.Query("SELECT * FROM bilety WHERE KtoZabralID=?", IDusers)
|
||||||
err = rows5.Scan(&IDbiletu, &KtoZabralID, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
checkErr(err)
|
||||||
checkErr3(err)
|
KosztBiletuSUMA = 0
|
||||||
if CzyZaplacony == "nie" {
|
for rows5.Next() {
|
||||||
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
err = rows5.Scan(&IDbiletu, &KtoZabralID, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
||||||
|
checkErr3(err)
|
||||||
|
if CzyZaplacony == "nie" {
|
||||||
|
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
t, _ := template.ParseFiles("placeOnline.gtpl")
|
||||||
t, _ := template.ParseFiles("placeOnline.gtpl")
|
checkErr(err)
|
||||||
checkErr(err)
|
type zaplac struct {
|
||||||
type zaplac struct {
|
UserView string
|
||||||
UserView string
|
Zaplac int
|
||||||
Zaplac int
|
}
|
||||||
}
|
z := zaplac{
|
||||||
z := zaplac{
|
UserView: User,
|
||||||
UserView: User,
|
Zaplac: KosztBiletuSUMA}
|
||||||
Zaplac: KosztBiletuSUMA}
|
|
||||||
|
|
||||||
t.ExecuteTemplate(w, "placeOnline.gtpl", z)
|
t.ExecuteTemplate(w, "placeOnline.gtpl", z)
|
||||||
rows5.Close()
|
rows5.Close()
|
||||||
db.Close()
|
db.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func zaplacono(w http.ResponseWriter, r *http.Request) {
|
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")
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
akt, err := db.Prepare("UPDATE bilety SET CzyZaplacony=? WHERE KtoZabralID=?")
|
akt, err := db.Prepare("UPDATE bilety SET CzyZaplacony=? WHERE KtoZabralID=?")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
up, err := akt.Exec("tak", KtoZabralID)
|
up, err := akt.Exec("tak", KtoZabralID)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
dzialanie, err := up.RowsAffected()
|
dzialanie, err := up.RowsAffected()
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
fmt.Println(dzialanie)
|
fmt.Println(dzialanie)
|
||||||
|
|
||||||
db.Close()
|
db.Close()
|
||||||
|
|
||||||
|
t, _ := template.ParseFiles("zaplacono.gtpl")
|
||||||
|
checkErr(err)
|
||||||
|
type zaplac struct {
|
||||||
|
UserView string
|
||||||
|
Zaplac int
|
||||||
|
}
|
||||||
|
z := zaplac{
|
||||||
|
UserView: User,
|
||||||
|
Zaplac: KosztBiletuSUMA}
|
||||||
|
|
||||||
|
t.ExecuteTemplate(w, "zaplacono.gtpl", z)
|
||||||
|
|
||||||
t, _ := template.ParseFiles("zaplacono.gtpl")
|
|
||||||
checkErr(err)
|
|
||||||
type zaplac struct {
|
|
||||||
UserView string
|
|
||||||
Zaplac int
|
|
||||||
}
|
}
|
||||||
z := zaplac{
|
|
||||||
UserView: User,
|
|
||||||
Zaplac: KosztBiletuSUMA}
|
|
||||||
|
|
||||||
t.ExecuteTemplate(w, "zaplacono.gtpl", z)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func zmianaPINU(w http.ResponseWriter, r *http.Request) {
|
func zmianaPINU(w http.ResponseWriter, r *http.Request) {
|
||||||
pinFROMsite := r.FormValue("pinFROMsite")
|
if User == "lost" {
|
||||||
RFIDblockORno := r.FormValue("RFID")
|
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
db.Close()
|
|
||||||
|
|
||||||
}
|
|
||||||
if RFIDblockORno == "RFIDblock" {
|
|
||||||
fmt.Fprintln(w, "*** --- Karta RFID została ZABLOKOWANA! --- *** \n")
|
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
|
||||||
checkErr(err)
|
|
||||||
|
|
||||||
akt, err := db.Prepare("UPDATE users SET Blokada=? WHERE IDusers=?")
|
|
||||||
checkErr(err)
|
|
||||||
up, err := akt.Exec("true", IDusers)
|
|
||||||
checkErr(err)
|
|
||||||
dzialanie, err := up.RowsAffected()
|
|
||||||
checkErr(err)
|
|
||||||
fmt.Println(dzialanie)
|
|
||||||
|
|
||||||
db.Close()
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if RFIDblockORno == "RFIDunlock" {
|
pinFROMsite := r.FormValue("pinFROMsite")
|
||||||
fmt.Fprintln(w, "*** --- Karta RFID została ODBLOKOWANA! --- *** \n")
|
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")
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
akt, err := db.Prepare("UPDATE users SET Blokada=? WHERE IDusers=?")
|
akt, err := db.Prepare("UPDATE users SET PIN=? WHERE IDusers=?")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
up, err := akt.Exec("false", IDusers)
|
up, err := akt.Exec(pinFROMsite, IDusers)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
dzialanie, err := up.RowsAffected()
|
dzialanie, err := up.RowsAffected()
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
@ -388,19 +428,58 @@ func zmianaPINU(w http.ResponseWriter, r *http.Request) {
|
|||||||
db.Close()
|
db.Close()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if RFIDblockORno == "RFIDblock" {
|
||||||
|
fmt.Fprintln(w, "*** --- Karta RFID została ZABLOKOWANA! --- *** \n")
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
akt, err := db.Prepare("UPDATE users SET Blokada=? WHERE IDusers=?")
|
||||||
|
checkErr(err)
|
||||||
|
up, err := akt.Exec("true", IDusers)
|
||||||
|
checkErr(err)
|
||||||
|
dzialanie, err := up.RowsAffected()
|
||||||
|
checkErr(err)
|
||||||
|
fmt.Println(dzialanie)
|
||||||
|
|
||||||
|
db.Close()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if RFIDblockORno == "RFIDunlock" {
|
||||||
|
fmt.Fprintln(w, "*** --- Karta RFID została ODBLOKOWANA! --- *** \n")
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
|
checkErr(err)
|
||||||
|
|
||||||
|
akt, err := db.Prepare("UPDATE users SET Blokada=? WHERE IDusers=?")
|
||||||
|
checkErr(err)
|
||||||
|
up, err := akt.Exec("false", IDusers)
|
||||||
|
checkErr(err)
|
||||||
|
dzialanie, err := up.RowsAffected()
|
||||||
|
checkErr(err)
|
||||||
|
fmt.Println(dzialanie)
|
||||||
|
|
||||||
|
db.Close()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func zmianaHasla(w http.ResponseWriter, r *http.Request) {
|
func zmianaHasla(w http.ResponseWriter, r *http.Request) {
|
||||||
//templatka przekierowuje do funkcji wylogowano
|
if User == "lost" {
|
||||||
t, _ := template.ParseFiles("zmianaHasla.gtpl")
|
http.Redirect(w, r, "http://localhost:9197/sesja", http.StatusSeeOther)
|
||||||
type zmhaslo struct {
|
} else {
|
||||||
UserView string
|
//templatka przekierowuje do funkcji wylogowano
|
||||||
|
t, _ := template.ParseFiles("zmianaHasla.gtpl")
|
||||||
|
type zmhaslo struct {
|
||||||
|
UserView string
|
||||||
|
}
|
||||||
|
wykonaj := zmhaslo{
|
||||||
|
UserView: User}
|
||||||
|
t.ExecuteTemplate(w, "zmianaHasla.gtpl", wykonaj)
|
||||||
}
|
}
|
||||||
wykonaj := zmhaslo{
|
|
||||||
UserView: User}
|
|
||||||
t.ExecuteTemplate(w, "zmianaHasla.gtpl", wykonaj)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
@ -438,6 +517,7 @@ func main() {
|
|||||||
http.HandleFunc("/menuDan", menuDan)
|
http.HandleFunc("/menuDan", menuDan)
|
||||||
http.HandleFunc("/zmianaPINU", zmianaPINU)
|
http.HandleFunc("/zmianaPINU", zmianaPINU)
|
||||||
http.HandleFunc("/zmianaHasla", zmianaHasla)
|
http.HandleFunc("/zmianaHasla", zmianaHasla)
|
||||||
|
http.HandleFunc("/sesja", sesja)
|
||||||
|
|
||||||
err := http.ListenAndServe(":9197", nil)
|
err := http.ListenAndServe(":9197", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user