Update main.go
This commit is contained in:
parent
55157e61fc
commit
04359ea161
151
main.go
151
main.go
@ -15,10 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//localhost-------------
|
KosztBiletuSUMA int
|
||||||
ID int
|
|
||||||
localHostDB string
|
|
||||||
localHost string
|
|
||||||
|
|
||||||
//logowanie ------------
|
//logowanie ------------
|
||||||
loginFROMsite string
|
loginFROMsite string
|
||||||
@ -56,8 +53,8 @@ var (
|
|||||||
//#############################################################################
|
//#############################################################################
|
||||||
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
|
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
|
||||||
//fmt.Println(localHostDB)
|
//fmt.Println(localHostDB)
|
||||||
t, _ := template.ParseFiles("StronaGlowna.gtpl")
|
t, _ := template.ParseFiles("StronaGlowna.gohtml")
|
||||||
t.Execute(w, localHost)
|
t.Execute(w, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
@ -99,11 +96,9 @@ func panel(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Println("method:", r.Method)
|
fmt.Println("method:", r.Method)
|
||||||
t, _ := template.ParseFiles("panel.gtpl")
|
t, _ := template.ParseFiles("panel.gtpl")
|
||||||
d := struct {
|
d := struct {
|
||||||
UserView string
|
UserView string
|
||||||
localHostView string
|
|
||||||
}{
|
}{
|
||||||
UserView: User,
|
UserView: User}
|
||||||
localHostView: localHost}
|
|
||||||
t.ExecuteTemplate(w, "panel.gtpl", d)
|
t.ExecuteTemplate(w, "panel.gtpl", d)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +108,6 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
t, _ := template.ParseFiles("wylogowano.gtpl")
|
t, _ := template.ParseFiles("wylogowano.gtpl")
|
||||||
d := struct {
|
d := struct {
|
||||||
localHostView string
|
|
||||||
loginFROMsiteView string
|
loginFROMsiteView string
|
||||||
passwordFROMsiteView string
|
passwordFROMsiteView string
|
||||||
IDusersView int
|
IDusersView int
|
||||||
@ -132,7 +126,6 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
|||||||
NazwaDaniaView string
|
NazwaDaniaView string
|
||||||
KosztDaniaView int
|
KosztDaniaView int
|
||||||
}{
|
}{
|
||||||
localHostView: localHost,
|
|
||||||
loginFROMsiteView: "",
|
loginFROMsiteView: "",
|
||||||
passwordFROMsiteView: "",
|
passwordFROMsiteView: "",
|
||||||
IDusersView: 0,
|
IDusersView: 0,
|
||||||
@ -156,21 +149,12 @@ func wylogowano(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
func login(w http.ResponseWriter, r *http.Request) {
|
func login(w http.ResponseWriter, r *http.Request) {
|
||||||
//fmt.Println(localHost)
|
|
||||||
//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")
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
// query
|
|
||||||
rows0, err := db.Query("SELECT * FROM users")
|
rows0, err := db.Query("SELECT * FROM users")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
@ -182,64 +166,35 @@ func login(w http.ResponseWriter, r *http.Request) {
|
|||||||
//fmt.Fprint(w, ". ")
|
//fmt.Fprint(w, ". ")
|
||||||
//fmt.Fprint(w, User)
|
//fmt.Fprint(w, User)
|
||||||
//fmt.Fprint(w, " \n")
|
//fmt.Fprint(w, " \n")
|
||||||
//if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
if Login == loginFROMsite {
|
if Login == loginFROMsite {
|
||||||
if Password == passwordFROMsite {
|
if Password == passwordFROMsite {
|
||||||
//fmt.Fprintln(w, zaloguj)
|
http.Redirect(w, r, "http://localhost:9197/panel", http.StatusSeeOther)
|
||||||
//fmt.Fprintln(w, usernameFROMsite)
|
panel(w, r)
|
||||||
//time.Sleep(3 * time.Second)
|
break
|
||||||
//if zaloguj == "Zalogowano!"
|
}
|
||||||
http.Redirect(w, r, "http://localhost:9197/panel", http.StatusSeeOther)
|
|
||||||
panel(w, r)
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println("method:", r.Method)
|
|
||||||
//r.Method = "GET"
|
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
t, _ := template.ParseFiles("login.gtpl")
|
t, _ := template.ParseFiles("login.gtpl")
|
||||||
d := struct {
|
t.Execute(w, nil)
|
||||||
localHost string
|
|
||||||
}{
|
|
||||||
localHost: localHost}
|
|
||||||
t.ExecuteTemplate(w, "login.gtpl", d)
|
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
//} else {
|
|
||||||
//fmt.Println("usernameFROMsite: ", r.Form["usernameFROMsite"])
|
|
||||||
//fmt.Println("passwordFROMsite: ", r.Form["passwordFROMsite"])
|
|
||||||
//if len(r.Form["usernameFROMsite"][0]) == 0 {
|
|
||||||
// goto Here
|
|
||||||
//}
|
|
||||||
//if len(r.Form["passwordFROMsite"][0]) == 0 {
|
|
||||||
// goto Here
|
|
||||||
//}
|
|
||||||
|
|
||||||
//obsługa blędnego wpisania loginu lub hasła
|
|
||||||
|
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
if loginFROMsite != Login {
|
if loginFROMsite != Login {
|
||||||
if loginFROMsite == "" {
|
if loginFROMsite == "" {
|
||||||
if passwordFROMsite != Password {
|
if passwordFROMsite != Password {
|
||||||
t, _ := template.ParseFiles("login.gtpl")
|
t, _ := template.ParseFiles("login.gtpl")
|
||||||
d := struct {
|
t.Execute(w, nil)
|
||||||
localHostView string
|
|
||||||
}{
|
|
||||||
localHostView: localHost}
|
|
||||||
t.ExecuteTemplate(w, "login.gtpl", d)
|
|
||||||
fmt.Fprint(w, "*** UWAGA! *** Błąd logowania! Login lub hasło nieprawidłowe. *** Spróbuj ponownie. ***")
|
fmt.Fprint(w, "*** UWAGA! *** Błąd logowania! Login lub hasło nieprawidłowe. *** Spróbuj ponownie. ***")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if passwordFROMsite != Password {
|
if passwordFROMsite != Password {
|
||||||
t, _ := template.ParseFiles("login.gtpl")
|
t, _ := template.ParseFiles("login.gtpl")
|
||||||
d := struct {
|
t.Execute(w, nil)
|
||||||
localHostView string
|
|
||||||
}{
|
|
||||||
localHostView: localHost}
|
|
||||||
t.ExecuteTemplate(w, "login.gtpl", d)
|
|
||||||
fmt.Fprint(w, "*** UWAGA! *** Błąd logowania! Login lub hasło nieprawidłowe. *** Spróbuj ponownie. ***")
|
fmt.Fprint(w, "*** UWAGA! *** Błąd logowania! Login lub hasło nieprawidłowe. *** Spróbuj ponownie. ***")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,11 +210,9 @@ 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")
|
t, _ := template.ParseFiles("menuDanNaglowek.gtpl")
|
||||||
d := struct {
|
d := struct {
|
||||||
localHostView string
|
UserView string
|
||||||
UserView string
|
|
||||||
}{
|
}{
|
||||||
localHostView: localHost,
|
UserView: User}
|
||||||
UserView: User}
|
|
||||||
t.ExecuteTemplate(w, "menuDanNaglowek.gtpl", d)
|
t.ExecuteTemplate(w, "menuDanNaglowek.gtpl", d)
|
||||||
//dania ----------------------------------
|
//dania ----------------------------------
|
||||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
||||||
@ -272,12 +225,10 @@ func menuDan(w http.ResponseWriter, r *http.Request) {
|
|||||||
//fmt.Printf("%d. %s, %d \n", IDdania, NazwaDania, KosztDania)
|
//fmt.Printf("%d. %s, %d \n", IDdania, NazwaDania, KosztDania)
|
||||||
t, _ := template.ParseFiles("menuDan.gtpl")
|
t, _ := template.ParseFiles("menuDan.gtpl")
|
||||||
d := struct {
|
d := struct {
|
||||||
localHostView string
|
|
||||||
IDdaniaView int
|
IDdaniaView int
|
||||||
NazwaDaniaView string
|
NazwaDaniaView string
|
||||||
KosztDaniaView int
|
KosztDaniaView int
|
||||||
}{
|
}{
|
||||||
localHostView: localHost,
|
|
||||||
IDdaniaView: IDdania,
|
IDdaniaView: IDdania,
|
||||||
NazwaDaniaView: NazwaDania,
|
NazwaDaniaView: NazwaDania,
|
||||||
KosztDaniaView: KosztDania}
|
KosztDaniaView: KosztDania}
|
||||||
@ -292,11 +243,9 @@ func menuDan(w http.ResponseWriter, r *http.Request) {
|
|||||||
func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.ParseFiles("historiaPosilkowNaglowek.gtpl")
|
t, _ := template.ParseFiles("historiaPosilkowNaglowek.gtpl")
|
||||||
d := struct {
|
d := struct {
|
||||||
localHostView string
|
UserView string
|
||||||
UserView string
|
|
||||||
}{
|
}{
|
||||||
localHostView: localHost,
|
UserView: User}
|
||||||
UserView: User}
|
|
||||||
t.ExecuteTemplate(w, "historiaPosilkowNaglowek.gtpl", d)
|
t.ExecuteTemplate(w, "historiaPosilkowNaglowek.gtpl", d)
|
||||||
|
|
||||||
//bilety ----------------------------------
|
//bilety ----------------------------------
|
||||||
@ -310,14 +259,12 @@ func historiaPosilkow(w http.ResponseWriter, r *http.Request) {
|
|||||||
if KtoZabral == User {
|
if KtoZabral == User {
|
||||||
t, _ := template.ParseFiles("historiaPosilkow.gtpl")
|
t, _ := template.ParseFiles("historiaPosilkow.gtpl")
|
||||||
d := struct {
|
d := struct {
|
||||||
localHostView string
|
|
||||||
IDbiletuView int
|
IDbiletuView int
|
||||||
KtoZabralView string
|
KtoZabralView string
|
||||||
DataCzasView string
|
DataCzasView string
|
||||||
KosztBiletuView int
|
KosztBiletuView int
|
||||||
CzyZaplaconyView bool
|
CzyZaplaconyView bool
|
||||||
}{
|
}{
|
||||||
localHostView: localHost,
|
|
||||||
IDbiletuView: IDbiletu,
|
IDbiletuView: IDbiletu,
|
||||||
KtoZabralView: KtoZabral,
|
KtoZabralView: KtoZabral,
|
||||||
DataCzasView: DataCzas,
|
DataCzasView: DataCzas,
|
||||||
@ -338,33 +285,29 @@ func platnosci(w http.ResponseWriter, r *http.Request) {
|
|||||||
//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 SUM(KosztBiletu)FROM bilety WHERE KtoZabral=?", User)
|
rows5, err := db.Query("SELECT * FROM bilety WHERE KtoZabral=?", User)
|
||||||
if err != nil {
|
checkErr(err)
|
||||||
fmt.Println(err)
|
KosztBiletuSUMA = 0
|
||||||
// os.Exit(1)
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
//for rows5.Next() {
|
|
||||||
//err = rows5.Scan(&KtoZabral, &KosztBiletu)
|
|
||||||
//checkErr3(err)
|
|
||||||
if KtoZabral == User {
|
|
||||||
t, _ := template.ParseFiles("platnosci.gtpl")
|
|
||||||
d := struct {
|
|
||||||
UserView string
|
|
||||||
KosztBiletuViewSuma int
|
|
||||||
}{
|
|
||||||
UserView: User,
|
|
||||||
KosztBiletuViewSuma: }
|
|
||||||
t.ExecuteTemplate(w, "platnosci.gtpl", d)
|
|
||||||
//break
|
|
||||||
}
|
|
||||||
//----------------------------------
|
|
||||||
//}
|
|
||||||
*/
|
|
||||||
for rows5.Next() {
|
for rows5.Next() {
|
||||||
rows5.Scan(&KtoZabral, &KosztBiletu)
|
err = rows5.Scan(&IDbiletu, &KtoZabral, &DataCzas, &KosztBiletu, &CzyZaplacony)
|
||||||
fmt.Printf("%v %v\n", KtoZabral, KosztBiletu)
|
checkErr3(err)
|
||||||
|
//if KtoZabral == User {
|
||||||
|
KosztBiletuSUMA = KosztBiletu + KosztBiletuSUMA
|
||||||
|
//}
|
||||||
|
//----------------------------------
|
||||||
}
|
}
|
||||||
|
fmt.Println(KosztBiletuSUMA)
|
||||||
|
t, _ := template.ParseFiles("platnosci.gtpl")
|
||||||
|
checkErr(err)
|
||||||
|
type zaplac struct {
|
||||||
|
UserView string
|
||||||
|
Zaplac int
|
||||||
|
}
|
||||||
|
z := zaplac{
|
||||||
|
UserView: User,
|
||||||
|
Zaplac: KosztBiletuSUMA}
|
||||||
|
|
||||||
|
t.ExecuteTemplate(w, "platnosci.gtpl", z)
|
||||||
rows5.Close()
|
rows5.Close()
|
||||||
db.Close()
|
db.Close()
|
||||||
}
|
}
|
||||||
@ -393,18 +336,6 @@ func checkErr3(err error) {
|
|||||||
//funkcja główna
|
//funkcja główna
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
func main() {
|
func main() {
|
||||||
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
|
||||||
checkErr(err)
|
|
||||||
rowsHost, err := db.Query("SELECT * FROM localhost")
|
|
||||||
checkErr2(err)
|
|
||||||
for rowsHost.Next() {
|
|
||||||
err = rowsHost.Scan(&ID, &localHostDB)
|
|
||||||
checkErr3(err)
|
|
||||||
}
|
|
||||||
localHost = localHostDB
|
|
||||||
rowsHost.Close()
|
|
||||||
db.Close()
|
|
||||||
|
|
||||||
http.HandleFunc("/", opisStołówkaZPM)
|
http.HandleFunc("/", opisStołówkaZPM)
|
||||||
http.HandleFunc("/login", login)
|
http.HandleFunc("/login", login)
|
||||||
http.HandleFunc("/panel", panel)
|
http.HandleFunc("/panel", panel)
|
||||||
@ -413,7 +344,7 @@ func main() {
|
|||||||
http.HandleFunc("/wylogowano", wylogowano)
|
http.HandleFunc("/wylogowano", wylogowano)
|
||||||
http.HandleFunc("/menuDan", menuDan)
|
http.HandleFunc("/menuDan", menuDan)
|
||||||
|
|
||||||
err = http.ListenAndServe(":9197", nil)
|
err := http.ListenAndServe(":9197", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("ListenAndServe: ", err)
|
log.Fatal("ListenAndServe: ", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user