From 09fc5a7c1ba5e125657c4fabeff06394531eeb8d Mon Sep 17 00:00:00 2001
From: Julien Dessaux
Date: Fri, 10 Sep 2021 17:40:57 +0200
Subject: Changed the way html pages title is set
---
internal/webui/html/base.html | 2 +-
internal/webui/html/login.html | 1 +
internal/webui/html/root.html | 1 +
internal/webui/login.go | 6 ++++--
internal/webui/root.go | 2 --
5 files changed, 7 insertions(+), 5 deletions(-)
(limited to 'internal')
diff --git a/internal/webui/html/base.html b/internal/webui/html/base.html
index 7522e94..28f131b 100644
--- a/internal/webui/html/base.html
+++ b/internal/webui/html/base.html
@@ -3,7 +3,7 @@
- {{ .Title }}
+ {{ template "title" . }}
diff --git a/internal/webui/html/login.html b/internal/webui/html/login.html
index 33e9f02..9aaa3cf 100644
--- a/internal/webui/html/login.html
+++ b/internal/webui/html/login.html
@@ -1,3 +1,4 @@
+{{ define "title"}}Login{{ end }}
{{ template "base" . }}
{{ define "main" }}
diff --git a/internal/webui/html/root.html b/internal/webui/html/root.html
index a293ee7..97441c8 100644
--- a/internal/webui/html/root.html
+++ b/internal/webui/html/root.html
@@ -1,3 +1,4 @@
+{{ define "title"}}Horaires des prochains trains à Crépieux la Pape{{ end }}
{{ template "base" . }}
{{ define "main" }}
diff --git a/internal/webui/login.go b/internal/webui/login.go
index 5469dd1..706cd29 100644
--- a/internal/webui/login.go
+++ b/internal/webui/login.go
@@ -17,13 +17,15 @@ var validPassword = regexp.MustCompile(`^.+$`)
var loginTemplate = template.Must(template.ParseFS(templatesFS, "html/base.html", "html/login.html"))
+type LoginPage struct{} // no variables to pass for now, but a previous error message would be good
+
// The login handler of the webui
func loginHandler(e *env, w http.ResponseWriter, r *http.Request) error {
if r.URL.Path == "/login" {
_, err := tryAndResumeSession(e, r)
if err == nil {
// already logged in
- http.Redirect(w, r, "/", http.StatusFound)
+ http.Redirect(w, r, "/", http.StatusFound) // TODO fail some other way, at least check if username parameter matches the logged in user
return nil
}
switch r.Method {
@@ -73,7 +75,7 @@ func loginHandler(e *env, w http.ResponseWriter, r *http.Request) error {
http.Redirect(w, r, "/", http.StatusFound)
return nil
case http.MethodGet:
- p := Page{Title: "Login"}
+ p := LoginPage{}
err := loginTemplate.ExecuteTemplate(w, "login.html", p)
if err != nil {
return newStatusError(http.StatusInternalServerError, err)
diff --git a/internal/webui/root.go b/internal/webui/root.go
index ab6fdcd..94f2169 100644
--- a/internal/webui/root.go
+++ b/internal/webui/root.go
@@ -15,7 +15,6 @@ var rootTemplate = template.Must(template.ParseFS(templatesFS, "html/base.html",
type Page struct {
User *model.User
Departures []model.Departure
- Title string
}
// The root handler of the webui
@@ -36,7 +35,6 @@ func rootHandler(e *env, w http.ResponseWriter, r *http.Request) error {
p := Page{
User: user,
Departures: departures,
- Title: "Horaires des prochains trains à Crépieux la Pape",
}
err = rootTemplate.ExecuteTemplate(w, "root.html", p)
if err != nil {
--
cgit v1.2.3