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 @@ - - Admin Login + + + Admin — přihlášení

Admin Login

-
- Uživatelské jméno:
- Heslo:
- + + {{if .}} +

Chybné uživatelské jméno nebo heslo.

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

Zpět na admin panel

\ No newline at end of file diff --git a/templates/assignment.html b/templates/assignment.html index e49d4e5..6a669ca 100644 --- a/templates/assignment.html +++ b/templates/assignment.html @@ -2,56 +2,269 @@ - + + Zadání šifry {{.Order}} + -

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

-

{{.Assignment}}

-
- {{if eq .Help 0}} -

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}} -
- {{if ne .Help 2}} - {{if .Wrong}}

Špatné řešení, zkus to znovu.

{{end}} -
- Řešení:
- -
- {{else}} -

- Souřadnice další šifry: - -
- -
- Nápověda k nalezení pozice: {{.PositionHint}} -

-

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

- {{end}} +
+
+

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

+
Aktuální úkol
+ +
+ {{.Assignment}} +
+ +
+ {{if eq .Help 0}} +
+
Požádat o malou nápovědu
+
+ + +
+
+ {{else if eq .Help 1}} +
+
Nápověda: {{.HelpText}}
+
+
Pokud se chcete vzdát a získat pozici další šifry:
+
+ + +
+
+
+ {{else}} +
+
Řešení: {{.Solution}}
+
+ {{end}} +
+ +
+ + {{if ne .Help 2}} + {{if .Wrong}}

Š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}} +
+
+ + - - \ No newline at end of file diff --git a/templates/login.html b/templates/login.html index cb6ff77..d667585 100644 --- a/templates/login.html +++ b/templates/login.html @@ -3,17 +3,123 @@ - Login + + Přihlášení + -

Login

-
- - -
- -
+
+
+

Přihlášení do týmu

+
Zadejte své týmové heslo
+ + {{if .}} +
Chybné heslo — zkuste to prosím znovu.
+ {{end}} + +
+
+ + +
+
+ +
+
+
+
\ No newline at end of file diff --git a/templates/team.html b/templates/team.html index ae3d62f..262dafe 100644 --- a/templates/team.html +++ b/templates/team.html @@ -3,18 +3,112 @@ + Tým: {{.TeamName}} + -

Tým: {{.TeamName}}

- Obtížnost: {{.Difficulty}}
- Poslední šifra : {{.LastCipher}}
- Penalizace: {{.Penalties}}
-
-
- -
+
+
+

Tým: {{.TeamName}}

+
Přehled týmu
+ +
+
+
Obtížnost: {{.Difficulty}}
+
Právě řeší šifru: {{.LastCipher}}
+
Penalizace (min): {{.Penalties}}
+
+ +
+ +
+
+
+
\ No newline at end of file