cipher templates
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="cs">
|
||||
|
||||
<head>
|
||||
<title>Zadání šifry {{.Order}}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Zadání šifry {{.Order}}</h1>
|
||||
<p>{{.Assignment}}</p>
|
||||
<hr>
|
||||
<form method="post">
|
||||
Řešení: <input type="text" name="assignment"><br>
|
||||
<input type="submit" value="Odeslat">
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
17
klice.go
17
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
templates.go
Normal file
16
templates.go
Normal file
@@ -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"))
|
||||
40
templates/assignment.html
Normal file
40
templates/assignment.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="cs">
|
||||
|
||||
<head>
|
||||
<title>Zadání šifry {{.Order}}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Zadání šifry {{.Order}}</h1>
|
||||
<p>{{.Assignment}}</p>
|
||||
<hr>
|
||||
{{if eq .HelpText ""}}
|
||||
<p>Požádat o malou nápovědu.</p>
|
||||
<form method="post">
|
||||
<input type="hidden" name="help" value="1">
|
||||
<input type="submit" value="Zobrazit nápovědu">
|
||||
</form>
|
||||
{{else if eq .Coordinates ""}}
|
||||
<p>Nápověda: {{.HelpText}}</p>
|
||||
<p>Vzdát se a ukázat pozici další šifry.</p>
|
||||
<form method="post">
|
||||
<input type="hidden" name="help" value="2">
|
||||
<input type="submit" value="Vzdát se">
|
||||
</form>
|
||||
{{else}}
|
||||
<p>Řešení: {{.Solution}}</p>
|
||||
{{end}}
|
||||
<hr>
|
||||
{{if eq .Coordinates ""}}
|
||||
<form method="post">
|
||||
Řešení: <input type="text" name="assignment"><br>
|
||||
<input type="submit" value="Odeslat">
|
||||
</form>
|
||||
{{else}}
|
||||
<p>Souřadnice další šifry: {{.Coordinates}}</p>
|
||||
<p>Nápověda k nalezení cíle: {{.FinalClue}}</p>
|
||||
{{end}}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login</title>
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user