diff --git a/main.go b/main.go index 3a1133d..3d98fdb 100644 --- a/main.go +++ b/main.go @@ -1,15 +1,22 @@ package main import ( + "html/template" "log" "net/http" - "streifling.com/jason/sicherheitsunterweisung/packages/data" "streifling.com/jason/sicherheitsunterweisung/packages/server" ) +func addUUIDs(uc *chan string, uuids *[]string) { + for uuid := range *uc { + (*uuids) = append(*uuids, uuid) + } +} + func main() { var i, j int64 + uuids := make([]string, 0) i, j = 1, 1 mux := http.NewServeMux() @@ -20,14 +27,19 @@ func main() { uuidChan := make(chan string) defer close(uuidChan) + go addUUIDs(&uuidChan, &uuids) mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/")))) - mux.HandleFunc("/", server.DisplayTable(db)) + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + template.Must(template.ParseFiles("templates/index.html", "templates/login.html")).Execute(w, nil) + }) mux.HandleFunc("/search/", server.DisplayResults(db)) mux.HandleFunc("/new-briefing/", server.DisplayForm(&i)) mux.HandleFunc("/add-participant/", server.AddParticipant(&i)) mux.HandleFunc("/submit-form/", server.SubmitForm(db, &i, &j)) mux.HandleFunc("/generate-uuid/", server.GenerateUUID(uuidChan)) + mux.HandleFunc("/internal-login/", server.DisplayTable(db)) + mux.HandleFunc("/external-login/", server.DisplayQuestionsIfOK(&uuids)) log.Fatalln(http.ListenAndServe(":8080", mux)) } diff --git a/packages/server/server.go b/packages/server/server.go index cc22ca3..ca44e63 100644 --- a/packages/server/server.go +++ b/packages/server/server.go @@ -92,3 +92,23 @@ func GenerateUUID(ch chan<- string) http.HandlerFunc { template.Must(template.ParseFiles("templates/form.html")).ExecuteTemplate(w, "uuid", uuid) } } + +func DisplayQuestionsIfOK(uuids *[]string) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if uuidIsOK(r.PostFormValue("login"), uuids) { + template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", nil) + } else { + template.Must(template.ParseFiles("templates/login.html")).ExecuteTemplate(w, "content", nil) + } + } +} + +// TODO: Delete uuid from uuids +func uuidIsOK(uuid string, uuids *[]string) bool { + for _, u := range *uuids { + if uuid == u { + return true + } + } + return false +} diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..0ed601e --- /dev/null +++ b/templates/login.html @@ -0,0 +1,16 @@ +{{ define "content" }} +
+

Login

+ + + + + + + +
+{{ end }}