A web blog and personal homepage engine written in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
875 B

package controllers
import (
"net/http"
"git.kirsle.net/apps/gophertype/pkg/glue"
"git.kirsle.net/apps/gophertype/pkg/responses"
"git.kirsle.net/apps/gophertype/pkg/session"
)
func init() {
glue.Register(glue.Endpoint{
Path: "/age-verify",
Methods: []string{"GET", "POST"},
Handler: AgeVerify,
})
}
// AgeVerify handles the age gate prompt page for NSFW sites.
func AgeVerify(w http.ResponseWriter, r *http.Request) {
var (
v = responses.NewTemplateVars(w, r)
next = r.FormValue("next")
confirm = r.FormValue("confirm")
)
if next == "" {
next = "/"
}
v.V["Next"] = next
if r.Method == http.MethodPost {
if confirm == "true" {
session := session.Get(r)
session.Values["age-ok"] = true
session.Save(r, w)
responses.Redirect(w, r, next)
return
}
}
responses.RenderTemplate(w, r, "_builtin/age-gate.gohtml", v)
}