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

  1. package controllers
  2. import (
  3. "net/http"
  4. "git.kirsle.net/apps/gophertype/pkg/glue"
  5. "git.kirsle.net/apps/gophertype/pkg/responses"
  6. "git.kirsle.net/apps/gophertype/pkg/session"
  7. )
  8. func init() {
  9. glue.Register(glue.Endpoint{
  10. Path: "/age-verify",
  11. Methods: []string{"GET", "POST"},
  12. Handler: AgeVerify,
  13. })
  14. }
  15. // AgeVerify handles the age gate prompt page for NSFW sites.
  16. func AgeVerify(w http.ResponseWriter, r *http.Request) {
  17. var (
  18. v = responses.NewTemplateVars(w, r)
  19. next = r.FormValue("next")
  20. confirm = r.FormValue("confirm")
  21. )
  22. if next == "" {
  23. next = "/"
  24. }
  25. v.V["Next"] = next
  26. if r.Method == http.MethodPost {
  27. if confirm == "true" {
  28. session := session.Get(r)
  29. session.Values["age-ok"] = true
  30. session.Save(r, w)
  31. responses.Redirect(w, r, next)
  32. return
  33. }
  34. }
  35. responses.RenderTemplate(w, r, "_builtin/age-gate.gohtml", v)
  36. }