From 68b3cc6218720e5302810a9e2ba4c2692af58fb7 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 2 Oct 2018 21:54:22 +0000 Subject: [PATCH] Move the idea of "tokens" into the client --- src/handlers.go | 65 ----------------------------------------------- theme/puzzle.html | 1 - theme/token.html | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 66 deletions(-) create mode 100644 theme/token.html diff --git a/src/handlers.go b/src/handlers.go index 88bf4f3..3d3984b 100644 --- a/src/handlers.go +++ b/src/handlers.go @@ -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) diff --git a/theme/puzzle.html b/theme/puzzle.html index 70130f3..86f5f65 100644 --- a/theme/puzzle.html +++ b/theme/puzzle.html @@ -87,7 +87,6 @@ document.addEventListener("DOMContentLoaded", init); diff --git a/theme/token.html b/theme/token.html new file mode 100644 index 0000000..aa457d5 --- /dev/null +++ b/theme/token.html @@ -0,0 +1,45 @@ + + + + Redeem Token + + + + + + + +

Redeem Token

+
+ + + + Team ID:
+ Token:
+ +
+ + +