100 lines
2.4 KiB
Go
100 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
//***************************************************************************
|
|
//funkcje sterujące
|
|
//***************************************************************************
|
|
|
|
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
|
|
t, _ := template.ParseFiles("StronaGlowna.gtpl")
|
|
t.Execute(w, nil)
|
|
|
|
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
|
|
checkErr(err)
|
|
// query
|
|
rows, err := db.Query("SELECT * FROM users")
|
|
checkErr(err)
|
|
var IDusers int64
|
|
var Username string
|
|
var Password string
|
|
var PIN int
|
|
|
|
for rows.Next() {
|
|
err = rows.Scan(&IDusers, &Username, &Password, &PIN)
|
|
checkErr(err)
|
|
fmt.Printf("%d, %s, %s, %d \n ", IDusers, Username, Password, PIN)
|
|
fmt.Fprintln("w \n", Username)
|
|
}
|
|
rows.Close()
|
|
|
|
db.Close()
|
|
|
|
}
|
|
|
|
func panel(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Println("method:", r.Method)
|
|
t, _ := template.ParseFiles("panel.gtpl")
|
|
t.Execute(w, nil)
|
|
}
|
|
|
|
func login(w http.ResponseWriter, r *http.Request) {
|
|
//Here:
|
|
fmt.Println("method:", r.Method)
|
|
if r.Method == "GET" {
|
|
t, _ := template.ParseFiles("login.gtpl")
|
|
t.Execute(w, nil)
|
|
} else {
|
|
r.ParseForm()
|
|
fmt.Println("username:", r.Form["username"])
|
|
fmt.Println("password:", r.Form["password"])
|
|
//if len(r.Form["username"][0]) == 0 {
|
|
// goto Here
|
|
//}
|
|
//if len(r.Form["password"][0]) == 0 {
|
|
// goto Here
|
|
//}
|
|
}
|
|
username := r.Form["username"]
|
|
password := r.Form["password"]
|
|
zaloguj := "Wpisane wartości:"
|
|
if r.Method == "POST" {
|
|
if zaloguj != "" {
|
|
fmt.Fprintln(w, zaloguj)
|
|
fmt.Fprintln(w, username)
|
|
fmt.Fprintln(w, password)
|
|
}
|
|
}
|
|
}
|
|
|
|
//***************************************************************************
|
|
//Bazy danych SQlite
|
|
//***************************************************************************
|
|
|
|
func checkErr(err error) {
|
|
if err != nil {
|
|
fmt.Println("Błąd")
|
|
}
|
|
}
|
|
|
|
//***************************************************************************
|
|
//funkcja główna
|
|
//***************************************************************************
|
|
func main() {
|
|
http.HandleFunc("/", opisStołówkaZPM)
|
|
http.HandleFunc("/login", login)
|
|
http.HandleFunc("/panel", panel)
|
|
err := http.ListenAndServe(":9197", nil)
|
|
if err != nil {
|
|
log.Fatal("ListenAndServe: ", err)
|
|
}
|
|
}
|