zaliczeniePP/main.go

69 lines
1.5 KiB
Go
Raw Normal View History

2018-11-21 23:47:31 +01:00
package main
2018-11-20 22:17:07 +01:00
2018-12-10 15:52:29 +01:00
import (
2018-12-28 22:10:55 +01:00
"database/sql"
2018-12-10 15:52:29 +01:00
"fmt"
"html/template"
"log"
"net/http"
2018-12-28 22:10:55 +01:00
_ "github.com/mattn/go-sqlite3"
2018-12-10 15:52:29 +01:00
)
2018-11-21 23:47:31 +01:00
2018-12-27 21:58:43 +01:00
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
2018-12-28 14:22:11 +01:00
t, _ := template.ParseFiles("StronaGlowna.gtpl")
2018-12-28 01:48:26 +01:00
t.Execute(w, nil)
2018-12-27 23:53:11 +01:00
}
2018-12-27 21:58:43 +01:00
2018-12-27 23:53:11 +01:00
func panel(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method)
t, _ := template.ParseFiles("panel.gtpl")
t.Execute(w, nil)
2018-12-10 16:09:22 +01:00
}
2018-12-10 18:00:33 +01:00
func login(w http.ResponseWriter, r *http.Request) {
2018-12-28 22:10:55 +01:00
//Here:
2018-12-10 18:00:33 +01:00
fmt.Println("method:", r.Method)
if r.Method == "GET" {
2018-12-28 14:22:11 +01:00
t, _ := template.ParseFiles("login.gtpl")
2018-12-10 18:00:33 +01:00
t.Execute(w, nil)
} else {
r.ParseForm()
fmt.Println("username:", r.Form["username"])
fmt.Println("password:", r.Form["password"])
2018-12-28 14:54:01 +01:00
//if len(r.Form["username"][0]) == 0 {
// goto Here
//}
//if len(r.Form["password"][0]) == 0 {
// goto Here
//}
2018-12-27 21:58:43 +01:00
}
2018-12-28 01:48:26 +01:00
username := r.Form["username"]
password := r.Form["password"]
zaloguj := "Wpisane wartości:"
2018-12-27 23:53:11 +01:00
if r.Method == "POST" {
if zaloguj != "" {
fmt.Fprintln(w, zaloguj)
fmt.Fprintln(w, username)
fmt.Fprintln(w, password)
}
2018-12-17 22:35:22 +01:00
}
}
2018-12-28 22:10:55 +01:00
func init() {
sql.Register("sqlite3", &SQLiteDriver{})
}
2018-11-21 23:47:31 +01:00
func main() {
2018-12-27 21:58:43 +01:00
http.HandleFunc("/", opisStołówkaZPM)
2018-12-10 18:00:33 +01:00
http.HandleFunc("/login", login)
2018-12-17 22:35:22 +01:00
http.HandleFunc("/panel", panel)
2018-12-10 18:00:33 +01:00
err := http.ListenAndServe(":9197", nil)
2018-12-10 15:52:29 +01:00
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
2018-12-28 22:10:55 +01:00
db, err := sql.Open("sqlite3", "./stolowka.db")
checkErr(err)
2018-12-10 18:00:33 +01:00
2018-11-21 23:47:31 +01:00
}