diff --git a/admin.go b/admin.go index d191832..ca9a1f6 100644 --- a/admin.go +++ b/admin.go @@ -15,7 +15,10 @@ type difficultyLevel struct { func adminLoginHandler(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: - http.ServeFile(w, r, "templates/adminLogin.html") + err := adminLoginTemplate.Execute(w, false) + if err != nil { + http.Error(w, "Could not render template", http.StatusInternalServerError) + } case http.MethodPost: if err := r.ParseForm(); err != nil { http.Error(w, "Error parsing form", http.StatusBadRequest) @@ -29,7 +32,10 @@ func adminLoginHandler(w http.ResponseWriter, r *http.Request) { ).Scan(new(int)) switch { case err == sql.ErrNoRows: - http.Error(w, "Invalid credentials", http.StatusUnauthorized) + err := adminLoginTemplate.Execute(w, true) + if err != nil { + http.Error(w, "Could not render template", http.StatusInternalServerError) + } case err != nil: http.Error(w, "Database error", http.StatusInternalServerError) default: @@ -82,7 +88,7 @@ func adminHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/admin/login", http.StatusSeeOther) return } - http.ServeFile(w, r, "templates/adminPanel.html") + http.ServeFileFS(w, r, templatesFS, "templates/adminPanel.html") } func adminTeamsHandler(w http.ResponseWriter, r *http.Request) { diff --git a/klice.go b/klice.go index 32a2bdf..cae5f4a 100644 --- a/klice.go +++ b/klice.go @@ -41,7 +41,10 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { err := db.QueryRow("SELECT 1 FROM teams WHERE password = ?", hashedPassword).Scan(new(int)) switch { case err == sql.ErrNoRows: - http.Error(w, "No team found", http.StatusUnauthorized) + err = LoginTemplate.Execute(w, true) + if err != nil { + http.Error(w, "Could not render template", http.StatusInternalServerError) + } return case err != nil: http.Error(w, "Could not retrieve team", http.StatusInternalServerError) @@ -68,7 +71,10 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { } } case http.MethodGet: - http.ServeFileFS(w, r, templatesFS, "templates/login.html") + err := LoginTemplate.Execute(w, false) + if err != nil { + http.Error(w, "Could not render template", http.StatusInternalServerError) + } default: http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) } diff --git a/templates.go b/templates.go index aabf31e..86dffb0 100644 --- a/templates.go +++ b/templates.go @@ -99,3 +99,5 @@ var AdminCipherTemplate = template.Must(template.ParseFS(templatesFS, "templates var AdminPositionsTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminPositions.html")) var AdminQRsTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminQR.html")) var AdminPenaltiesTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminPenalties.html")) +var LoginTemplate = template.Must(template.ParseFS(templatesFS, "templates/login.html")) +var adminLoginTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminLogin.html")) diff --git a/templates/adminLogin.html b/templates/adminLogin.html index ec8790b..c5c1309 100644 --- a/templates/adminLogin.html +++ b/templates/adminLogin.html @@ -2,17 +2,33 @@
- -{{.Assignment}}
-Požádat o malou nápovědu.
- - {{else if eq .Help 1}} -Nápověda: {{.HelpText}}
-Vzdát se a ukázat pozici další šifry.
- - {{else}} -Řešení: {{.Solution}}
- {{end}} -Špatné řešení, zkus to znovu.
{{end}} - - {{else}} -
- Souřadnice další šifry:
-
-
-
-
- Nápověda k nalezení pozice: {{.PositionHint}}
-
Nápověda k nalezení cíle: {{.FinalClue}}
- {{end}} +Špatné řešení, zkus to znovu.
{{end}} + + {{else}} +Souřadnice další šifry
+Nápověda k nalezení pozice: {{.PositionHint}} +
+Nápověda k nalezení cíle: {{.FinalClue}}
+