From 55e6be72392499ea446651cc10fe164e13c023bc Mon Sep 17 00:00:00 2001 From: Teajey <21069848+Teajey@users.noreply.github.com> Date: Sun, 7 Dec 2025 12:43:55 +0900 Subject: [PATCH] Add text templates to endpoints --- http/response/handler.go | 2 ++ http/templates/text/foreign_wishlist.gotmpl | 0 http/templates/text/group_page.gotmpl | 0 http/templates/text/home.gotmpl | 0 http/templates/text/login.gotmpl | 8 ++++++++ .../text/public_foreign_wishlist.gotmpl | 0 http/templates/text/public_group_page.gotmpl | 0 http/templates/text/register.gotmpl | 11 +++++++++++ http/templates/text/template.go | 17 +++++++++++++++++ 9 files changed, 38 insertions(+) create mode 100644 http/templates/text/foreign_wishlist.gotmpl create mode 100644 http/templates/text/group_page.gotmpl create mode 100644 http/templates/text/home.gotmpl create mode 100644 http/templates/text/login.gotmpl create mode 100644 http/templates/text/public_foreign_wishlist.gotmpl create mode 100644 http/templates/text/public_group_page.gotmpl create mode 100644 http/templates/text/register.gotmpl create mode 100644 http/templates/text/template.go diff --git a/http/response/handler.go b/http/response/handler.go index 3962387..33c0d7c 100644 --- a/http/response/handler.go +++ b/http/response/handler.go @@ -6,6 +6,7 @@ import ( "lishwist/http/session" "lishwist/http/templates" + "lishwist/http/templates/text" "github.com/Teajey/rsvp" ) @@ -18,6 +19,7 @@ type ServeMux struct { func NewServeMux(store *session.Store) *ServeMux { mux := rsvp.NewServeMux() mux.Config.HtmlTemplate = templates.Template + mux.Config.TextTemplate = text.Template return &ServeMux{ inner: mux, store: store, diff --git a/http/templates/text/foreign_wishlist.gotmpl b/http/templates/text/foreign_wishlist.gotmpl new file mode 100644 index 0000000..e69de29 diff --git a/http/templates/text/group_page.gotmpl b/http/templates/text/group_page.gotmpl new file mode 100644 index 0000000..e69de29 diff --git a/http/templates/text/home.gotmpl b/http/templates/text/home.gotmpl new file mode 100644 index 0000000..e69de29 diff --git a/http/templates/text/login.gotmpl b/http/templates/text/login.gotmpl new file mode 100644 index 0000000..39e15ec --- /dev/null +++ b/http/templates/text/login.gotmpl @@ -0,0 +1,8 @@ +Just a normal login form. Takes the following form values: + +username string +password string + +Upon successful login, a redirect to the same URL on the protected router is issued. + +A registration page is also available at /register diff --git a/http/templates/text/public_foreign_wishlist.gotmpl b/http/templates/text/public_foreign_wishlist.gotmpl new file mode 100644 index 0000000..e69de29 diff --git a/http/templates/text/public_group_page.gotmpl b/http/templates/text/public_group_page.gotmpl new file mode 100644 index 0000000..e69de29 diff --git a/http/templates/text/register.gotmpl b/http/templates/text/register.gotmpl new file mode 100644 index 0000000..fec6589 --- /dev/null +++ b/http/templates/text/register.gotmpl @@ -0,0 +1,11 @@ +Register with the following form values: + +username string +newPassword string +confirmPassword string + +All must be provided, username must be unique, newPassword and confirmPassword must be identical. + +It's worth considering that having two password form parameters isn't very helpful on the command line, it's only really useful to the browser. +Therefore, it might be a good idea to have Javascript check these two fields are identical, and submit, rather than having this +checked by the server. Meaning only one password field needs to be submitted to the server. That does block non-Javascript browsers tho :^P diff --git a/http/templates/text/template.go b/http/templates/text/template.go new file mode 100644 index 0000000..3851a19 --- /dev/null +++ b/http/templates/text/template.go @@ -0,0 +1,17 @@ +package text + +import ( + "text/template" +) + +var Template *template.Template + +func init() { + Template = load() +} + +func load() *template.Template { + t := template.Must(template.ParseGlob("templates/text/*.gotmpl")) + return t +} +