diff --git a/config.go b/config.go index 5214296..9cbf013 100644 --- a/config.go +++ b/config.go @@ -28,6 +28,7 @@ func initArgs() { flag.BoolVar(&randomizeTokens, "random-tokens", false, "Generate tokens with some random bytes") flag.StringVar(&corsHeader, "cors-header", defaultCorsHeader, "Access-Control-Allow-Origin HTTP request header") flag.StringVar(&password, "entry-pwd", defaultPassword, "Password provided in POST JSON to authenticate") + flag.BoolVar(&reuseTokens, "reuse-tokens", false, "Generate a single token for every player") } func parseArgs() { diff --git a/handlers.go b/handlers.go index ca33237..ebdc8e5 100644 --- a/handlers.go +++ b/handlers.go @@ -18,8 +18,9 @@ const ( ) var ( - corsHeader string - password string + corsHeader string + password string + reuseTokens bool ) func boardHandler(w http.ResponseWriter, r *http.Request) { @@ -214,7 +215,14 @@ func newKeyHandler(w http.ResponseWriter, r *http.Request) { errorResponse(400, "Unable to convert request to JSON: "+jsonErr.Error(), w, r) return } - key, sqlErr := newKeySql(newKey.PlayerID) + var key *Key + var sqlErr error + if reuseTokens { + key, sqlErr = keyByPlayer(newKey.PlayerID) + } + if (sqlErr != nil && reuseTokens) || !reuseTokens { + key, sqlErr = newKeySql(newKey.PlayerID) + } if sqlErr != nil { fmt.Println(sqlErr) errorResponse(500, "Key could not be created: "+sqlErr.Error(), w, r)