aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-10 17:40:57 +0200
committerJulien Dessaux2021-09-10 17:40:57 +0200
commit09fc5a7c1ba5e125657c4fabeff06394531eeb8d (patch)
tree19f8f0011cec4c480736f72bcdcfa5c68a541c58
parentRefactoring of navitia mocking code for the webui (diff)
downloadtrains-09fc5a7c1ba5e125657c4fabeff06394531eeb8d.tar.gz
trains-09fc5a7c1ba5e125657c4fabeff06394531eeb8d.tar.bz2
trains-09fc5a7c1ba5e125657c4fabeff06394531eeb8d.zip
Changed the way html pages title is set
-rw-r--r--internal/webui/html/base.html2
-rw-r--r--internal/webui/html/login.html1
-rw-r--r--internal/webui/html/root.html1
-rw-r--r--internal/webui/login.go6
-rw-r--r--internal/webui/root.go2
5 files changed, 7 insertions, 5 deletions
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 @@
<html lang="en">
<head>
<meta charset="utf-8">
- <title>{{ .Title }}</title>
+ <title>{{ template "title" . }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="/static/favicon.png" />
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 {