mirror of https://github.com/dirtbags/moth.git
Move the idea of "tokens" into the client
This commit is contained in:
parent
25a12c00c2
commit
68b3cc6218
|
@ -174,70 +174,6 @@ func (ctx *Instance) registerHandler(w http.ResponseWriter, req *http.Request) {
|
|||
)
|
||||
}
|
||||
|
||||
func (ctx *Instance) tokenHandler(w http.ResponseWriter, req *http.Request) {
|
||||
teamid := req.FormValue("id")
|
||||
token := req.FormValue("token")
|
||||
|
||||
var category string
|
||||
var points int
|
||||
var fluff string
|
||||
|
||||
stoken := strings.Replace(token, ":", " ", 2)
|
||||
n, err := fmt.Sscanf(stoken, "%s %d %s", &category, &points, &fluff)
|
||||
if err != nil || n != 3 {
|
||||
respond(
|
||||
w, req, Fail,
|
||||
"Malformed token",
|
||||
"That doesn't look like a token: %v.", err,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (category == "") || (points <= 0) {
|
||||
respond(
|
||||
w, req, Fail,
|
||||
"Weird token",
|
||||
"That token doesn't make any sense.",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
f, err := ctx.OpenCategoryFile(category, "tokens.txt")
|
||||
if err != nil {
|
||||
respond(
|
||||
w, req, Fail,
|
||||
"Cannot list valid tokens",
|
||||
err.Error(),
|
||||
)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Make sure the token is in the list
|
||||
if !hasLine(f, token) {
|
||||
respond(
|
||||
w, req, Fail,
|
||||
"Unrecognized token",
|
||||
"I don't recognize that token. Did you type in the whole thing?",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if err := ctx.AwardPoints(teamid, category, points); err != nil {
|
||||
respond(
|
||||
w, req, Fail,
|
||||
"Error awarding points",
|
||||
err.Error(),
|
||||
)
|
||||
return
|
||||
}
|
||||
respond(
|
||||
w, req, Success,
|
||||
"Points awarded",
|
||||
"%d points for %s!", points, teamid,
|
||||
)
|
||||
}
|
||||
|
||||
func (ctx *Instance) answerHandler(w http.ResponseWriter, req *http.Request) {
|
||||
teamid := req.FormValue("id")
|
||||
category := req.FormValue("cat")
|
||||
|
@ -368,7 +304,6 @@ func (ctx *Instance) staticHandler(w http.ResponseWriter, req *http.Request) {
|
|||
func (ctx *Instance) BindHandlers(mux *http.ServeMux) {
|
||||
mux.HandleFunc(ctx.Base+"/", ctx.staticHandler)
|
||||
mux.HandleFunc(ctx.Base+"/register", ctx.registerHandler)
|
||||
mux.HandleFunc(ctx.Base+"/token", ctx.tokenHandler)
|
||||
mux.HandleFunc(ctx.Base+"/answer", ctx.answerHandler)
|
||||
mux.HandleFunc(ctx.Base+"/content/", ctx.contentHandler)
|
||||
mux.HandleFunc(ctx.Base+"/puzzles.json", ctx.puzzlesHandler)
|
||||
|
|
|
@ -87,7 +87,6 @@ document.addEventListener("DOMContentLoaded", init);
|
|||
<ul>
|
||||
<li><a href="puzzle-list.html">Puzzles</a></li>
|
||||
<li><a href="scoreboard.html">Scoreboard</a></li>
|
||||
<li><a href="scoring.html">Scoring</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</body>
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Redeem Token</title>
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="icon" href="res/icon.svg" type="image/svg+xml">
|
||||
<link rel="icon" href="res/icon.png" type="image/png">
|
||||
<script>
|
||||
function erpdert() {
|
||||
let vals = document.querySelector("[name=token]").value.split(":");
|
||||
document.querySelector("[name=cat]").value = vals[0];
|
||||
document.querySelector("[name=points]").value = vals[1];
|
||||
document.querySelector("[name=answer]").value = vals[2];
|
||||
}
|
||||
|
||||
function init() {
|
||||
document.querySelector("[name=token]").addEventListener("input", erpdert);
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Redeem Token</h1>
|
||||
<form action="token" method="post">
|
||||
<input type="hidden" name="cat">
|
||||
<input type="hidden" name="points">
|
||||
<input type="hidden" name="answer">
|
||||
Team ID: <input type="text" name="id"> <br>
|
||||
Token: <input type="text" name="token"> <br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="puzzle-list.html">Puzzles</a></li>
|
||||
<li><a href="scoreboard.html">Scoreboard</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue