* Remove Negroni in favor of the standard net/http server. * Remove gorilla/mux in favor of the standard net/http NewServeMux. * Remove gorilla/sessions in favor of Redis session_id cookie. * Remove the hacky glue controllers setup in favor of regular defined routes in the router.go file directly. * Update all Go dependencies for Go 1.24 * Move and centralize all the HTTP middlewares. * Add middlewares for Logging and Recovery to replace Negroni's.
35 lines
683 B
Go
35 lines
683 B
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.kirsle.net/apps/gophertype/pkg/responses"
|
|
"git.kirsle.net/apps/gophertype/pkg/session"
|
|
)
|
|
|
|
// 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.AgeOK = true
|
|
session.Save(w)
|
|
responses.Redirect(w, r, next)
|
|
return
|
|
}
|
|
}
|
|
|
|
responses.RenderTemplate(w, r, "_builtin/age-gate.gohtml", v)
|
|
}
|