Login für eingeladene Prüflinge implementiert
This commit is contained in:
parent
608879d008
commit
726c8b6dcb
16
main.go
16
main.go
@ -1,15 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||||
"streifling.com/jason/sicherheitsunterweisung/packages/server"
|
"streifling.com/jason/sicherheitsunterweisung/packages/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func addUUIDs(uc *chan string, uuids *[]string) {
|
||||||
|
for uuid := range *uc {
|
||||||
|
(*uuids) = append(*uuids, uuid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var i, j int64
|
var i, j int64
|
||||||
|
uuids := make([]string, 0)
|
||||||
i, j = 1, 1
|
i, j = 1, 1
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
@ -20,14 +27,19 @@ func main() {
|
|||||||
|
|
||||||
uuidChan := make(chan string)
|
uuidChan := make(chan string)
|
||||||
defer close(uuidChan)
|
defer close(uuidChan)
|
||||||
|
go addUUIDs(&uuidChan, &uuids)
|
||||||
|
|
||||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
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("/search/", server.DisplayResults(db))
|
||||||
mux.HandleFunc("/new-briefing/", server.DisplayForm(&i))
|
mux.HandleFunc("/new-briefing/", server.DisplayForm(&i))
|
||||||
mux.HandleFunc("/add-participant/", server.AddParticipant(&i))
|
mux.HandleFunc("/add-participant/", server.AddParticipant(&i))
|
||||||
mux.HandleFunc("/submit-form/", server.SubmitForm(db, &i, &j))
|
mux.HandleFunc("/submit-form/", server.SubmitForm(db, &i, &j))
|
||||||
mux.HandleFunc("/generate-uuid/", server.GenerateUUID(uuidChan))
|
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))
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
@ -92,3 +92,23 @@ func GenerateUUID(ch chan<- string) http.HandlerFunc {
|
|||||||
template.Must(template.ParseFiles("templates/form.html")).ExecuteTemplate(w, "uuid", uuid)
|
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
|
||||||
|
}
|
||||||
|
16
templates/login.html
Normal file
16
templates/login.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{{ define "content" }}
|
||||||
|
<form>
|
||||||
|
<h2>Login</h2>
|
||||||
|
|
||||||
|
<label for="login-input">Code</label>
|
||||||
|
<input type="text" name="login" id="login-input" />
|
||||||
|
|
||||||
|
<button type="submit" hx-post="/external-login/" hx-target="#content">
|
||||||
|
Anmelden
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button type="submit" hx-post="/internal-login/" hx-target="#content">
|
||||||
|
Intern
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
{{ end }}
|
Loading…
x
Reference in New Issue
Block a user