From 488084f1bb72ddac3e5a55a571f18b92498863de Mon Sep 17 00:00:00 2001 From: prokopparuzek Date: Sun, 14 Sep 2025 19:05:41 +0200 Subject: [PATCH] cipher templates --- assignment.html | 18 -------------- klice.go | 17 +++++++++++-- templates.go | 16 ++++++++++++ templates/assignment.html | 40 ++++++++++++++++++++++++++++++ login.html => templates/login.html | 1 - 5 files changed, 71 insertions(+), 21 deletions(-) delete mode 100644 assignment.html create mode 100644 templates.go create mode 100644 templates/assignment.html rename login.html => templates/login.html (83%) diff --git a/assignment.html b/assignment.html deleted file mode 100644 index 50f7edc..0000000 --- a/assignment.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - Zadání šifry {{.Order}} - - - -

Zadání šifry {{.Order}}

-

{{.Assignment}}

-
-
- Řešení:
- -
- - - \ No newline at end of file diff --git a/klice.go b/klice.go index 92b4333..758aeb8 100644 --- a/klice.go +++ b/klice.go @@ -5,6 +5,7 @@ import ( "database/sql" "encoding/hex" "fmt" + "html/template" "io" "net/http" "os" @@ -58,7 +59,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/team", http.StatusSeeOther) } } else if r.Method == http.MethodGet { - loginPage, err := os.Open("login.html") + loginPage, err := os.Open("templates/login.html") if err != nil { http.Error(w, "Could not open login page", http.StatusInternalServerError) return @@ -153,7 +154,19 @@ func qrHandler(w http.ResponseWriter, r *http.Request) { return } - fmt.Fprintf(w, "QR Code: %s, Position ID: %d, Cipher ID: %d, Assignment: %s", uid, positionID, cipherID, assignment) + CipherTemplateData := CipherTemplateS{ + Order: uint(cipherID), + Assignment: template.HTML(assignment), + HelpText: "", + FinalClue: "", + Coordinates: "", + Solution: "", + } + err = CipherTemplate.Execute(w, CipherTemplateData) + if err != nil { + http.Error(w, "Could not render template", http.StatusInternalServerError) + return + } } } diff --git a/templates.go b/templates.go new file mode 100644 index 0000000..387b08d --- /dev/null +++ b/templates.go @@ -0,0 +1,16 @@ +package main + +import ( + "html/template" +) + +type CipherTemplateS struct { + Order uint + Assignment template.HTML + HelpText string + FinalClue string + Coordinates string + Solution string +} + +var CipherTemplate = template.Must(template.ParseFiles("templates/assignment.html")) diff --git a/templates/assignment.html b/templates/assignment.html new file mode 100644 index 0000000..71374aa --- /dev/null +++ b/templates/assignment.html @@ -0,0 +1,40 @@ + + + + + Zadání šifry {{.Order}} + + + +

Zadání šifry {{.Order}}

+

{{.Assignment}}

+
+ {{if eq .HelpText ""}} +

Požádat o malou nápovědu.

+
+ + +
+ {{else if eq .Coordinates ""}} +

Nápověda: {{.HelpText}}

+

Vzdát se a ukázat pozici další šifry.

+
+ + +
+ {{else}} +

Řešení: {{.Solution}}

+ {{end}} +
+ {{if eq .Coordinates ""}} +
+ Řešení:
+ +
+ {{else}} +

Souřadnice další šifry: {{.Coordinates}}

+

Nápověda k nalezení cíle: {{.FinalClue}}

+ {{end}} + + + \ No newline at end of file diff --git a/login.html b/templates/login.html similarity index 83% rename from login.html rename to templates/login.html index 0c68620..cb6ff77 100644 --- a/login.html +++ b/templates/login.html @@ -3,7 +3,6 @@ - Login