Age Gate: Allow single-page exceptions with ?over18=1

This commit is contained in:
Noah 2019-01-01 13:31:01 -08:00
parent 0943ff34b1
commit 87f53c9895

View File

@ -4,9 +4,9 @@ import (
"net/http"
"strings"
"github.com/kirsle/blog/models/settings"
"github.com/kirsle/blog/src/responses"
"github.com/kirsle/blog/src/sessions"
"github.com/kirsle/blog/models/settings"
"github.com/urfave/negroni"
)
@ -48,9 +48,12 @@ func AgeGate(verifyHandler func(http.ResponseWriter, *http.Request)) negroni.Han
session := sessions.Get(r)
if val, _ := session.Values["age-ok"].(bool); !val {
// They haven't been verified.
// Allow single-page loads with ?over18=1 in query parameter.
if r.FormValue("over18") == "" {
responses.Redirect(w, "/age-verify?next="+r.URL.Path)
return
}
}
next(w, r)
}