handle answers
This commit is contained in:
15
klice.go
15
klice.go
@@ -206,6 +206,7 @@ func qrHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
FinalClue: "",
|
FinalClue: "",
|
||||||
Coordinates: "",
|
Coordinates: "",
|
||||||
Solution: "",
|
Solution: "",
|
||||||
|
Wrong: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// get penalties for this task and team
|
// get penalties for this task and team
|
||||||
@@ -238,6 +239,20 @@ func qrHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
db.Exec("UPDATE penalties SET minutes = 30 WHERE team_id = ? AND task_id = ?", teamID, taskID)
|
db.Exec("UPDATE penalties SET minutes = 30 WHERE team_id = ? AND task_id = ?", teamID, taskID)
|
||||||
db.Exec("UPDATE teams SET penalty = penalty + 30 WHERE id = ?", teamID)
|
db.Exec("UPDATE teams SET penalty = penalty + 30 WHERE id = ?", teamID)
|
||||||
db.Exec("UPDATE teams SET last_cipher = ? WHERE id = ?", order+1, teamID)
|
db.Exec("UPDATE teams SET last_cipher = ? WHERE id = ?", order+1, teamID)
|
||||||
|
} else if answer := r.FormValue("solution"); answer != "" { // answer submission
|
||||||
|
var correctAnswer string
|
||||||
|
err = db.QueryRow("SELECT solution FROM CIPHERS WHERE id = ?", cipherID).Scan(&correctAnswer)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Could not retrieve solution", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.EqualFold(strings.TrimSpace(answer), strings.TrimSpace(correctAnswer)) {
|
||||||
|
// correct answer, move to next task
|
||||||
|
db.Exec("UPDATE teams SET last_cipher = ? WHERE id = ?", order+1, teamID)
|
||||||
|
help = 2
|
||||||
|
} else {
|
||||||
|
CipherTemplateData.Wrong = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type CipherTemplateS struct {
|
|||||||
Coordinates string
|
Coordinates string
|
||||||
Solution string
|
Solution string
|
||||||
Help int
|
Help int
|
||||||
|
Wrong bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var CipherTemplate = template.Must(template.ParseFiles("templates/assignment.html"))
|
var CipherTemplate = template.Must(template.ParseFiles("templates/assignment.html"))
|
||||||
|
|||||||
@@ -27,8 +27,9 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
<hr>
|
<hr>
|
||||||
{{if ne .Help 2}}
|
{{if ne .Help 2}}
|
||||||
|
{{if .Wrong}}<p style="color:red;">Špatné řešení, zkus to znovu.</p>{{end}}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
Řešení: <input type="text" name="assignment"><br>
|
Řešení: <input type="text" name="solution"><br>
|
||||||
<input type="submit" value="Odeslat">
|
<input type="submit" value="Odeslat">
|
||||||
</form>
|
</form>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|||||||
Reference in New Issue
Block a user