Read PODSTALK_ALLOW_SIGNUP env var to control sign-up

This commit is contained in:
2026-08-19 10:20:05 -04:00
parent 92677e8d5c
commit d9b9876875
+20 -1
View File
@@ -8,6 +8,8 @@ import (
"net/http"
"os"
"runtime/debug"
"strconv"
"strings"
"golang.org/x/crypto/bcrypt"
@@ -42,6 +44,11 @@ func main() {
baseURL = "http://localhost:8080"
}
allowSignup := false
if v := os.Getenv("PODSTALK_ALLOW_SIGNUP"); v != "" {
allowSignup = envBool(v)
}
st, err := store.New(dbPath)
if err != nil {
log.Fatalf("failed to open database: %v", err)
@@ -58,7 +65,7 @@ func main() {
authMid := &handler.AuthMiddleware{Store: st, Sessions: sessions}
authH := &handler.AuthHandler{Store: st, Sessions: sessions, Tpl: tpl}
authH := &handler.AuthHandler{Store: st, Sessions: sessions, Tpl: tpl, AllowSignup: allowSignup}
epH := &handler.EpisodeHandler{
Store: st,
Tpl: tpl,
@@ -157,3 +164,15 @@ func envOrDefault(key, def string) string {
}
return def
}
// envBool interprets a string as a truthy boolean.
func envBool(v string) bool {
if b, err := strconv.ParseBool(v); err == nil {
return b
}
switch strings.ToLower(strings.TrimSpace(v)) {
case "yes", "on":
return true
}
return false
}