From bf2d515ad236632c5acae9da0bcb388d118f6000 Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Thu, 27 Jul 2023 15:57:17 +0200 Subject: [PATCH] Refactor Site-Wide Data --- templates/login.html | 4 ++-- templates/passwd.html | 4 ++-- view-login.go | 13 +++++++++++-- view-passwd.go | 9 ++++++--- view.go | 2 -- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/templates/login.html b/templates/login.html index ae9a0fa..632b860 100644 --- a/templates/login.html +++ b/templates/login.html @@ -11,10 +11,10 @@

S'identifier

- {{if .WrongUser}} + {{if .DataWrongUser}}
Identifiant invalide.
{{end}} - {{if .WrongPass}} + {{if .DataWrongPass}}
Mot de passe invalide.
{{end}} {{if .Common.ErrorMessage}} diff --git a/templates/passwd.html b/templates/passwd.html index f85b709..9e4d511 100644 --- a/templates/passwd.html +++ b/templates/passwd.html @@ -23,7 +23,7 @@ - {{if .TooShortError}} + {if .DataTooShortError}}
Le mot de passe choisi est trop court (minimum 8 caractères).
@@ -32,7 +32,7 @@ - {{if .NoMatchError}} + {if .DataNoMatchError}}
Les deux mots de passe entrés ne correspondent pas.
diff --git a/view-login.go b/view-login.go index f53b294..7cf8b80 100644 --- a/view-login.go +++ b/view-login.go @@ -73,17 +73,26 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo { log.Printf("%v", username) data.Common.ErrorMessage = err.Error() } - templateLogin.Execute(w, data) + // templateLogin.Execute(w, data) + execTemplate(w, templateLogin, data.Common, NestedLoginTplData{}, *config, data) } http.Redirect(w, r, "/", http.StatusTemporaryRedirect) return loginInfo } else if r.Method == "GET" { - templateLogin.Execute(w, LoginFormData{ + execTemplate(w, templateLogin, NestedCommonTplData{ + CanAdmin: false, + CanInvite: true, + LoggedIn: false}, NestedLoginTplData{}, *config, LoginFormData{ Common: NestedCommonTplData{ CanAdmin: false, CanInvite: true, LoggedIn: false}}) + // templateLogin.Execute(w, LoginFormData{ + // Common: NestedCommonTplData{ + // CanAdmin: false, + // CanInvite: true, + // LoggedIn: false}}) return nil } else { http.Error(w, "Unsupported method", http.StatusBadRequest) diff --git a/view-passwd.go b/view-passwd.go index ee2b3ce..882d980 100644 --- a/view-passwd.go +++ b/view-passwd.go @@ -54,7 +54,8 @@ func handleLostPassword(w http.ResponseWriter, r *http.Request) { err = passwordLost(user, config, ldapNewConn) } data.Common.CanAdmin = false - templateLostPasswordPage.Execute(w, data) + // templateLostPasswordPage.Execute(w, data) + execTemplate(w, templateLostPasswordPage, data.Common, NestedLoginTplData{}, *config, data) } func handleFoundPassword(w http.ResponseWriter, r *http.Request) { @@ -108,7 +109,8 @@ func handleFoundPassword(w http.ResponseWriter, r *http.Request) { } } data.Common.CanAdmin = false - templateFoundPasswordPage.Execute(w, data) + // templateFoundPasswordPage.Execute(w, data) + execTemplate(w, templateFoundPasswordPage, data.Common, data.Login, *config, data) } func handlePasswd(w http.ResponseWriter, r *http.Request) { @@ -153,5 +155,6 @@ func handlePasswd(w http.ResponseWriter, r *http.Request) { } } data.Common.CanAdmin = false - templatePasswd.Execute(w, data) + // templatePasswd.Execute(w, data) + execTemplate(w, templatePasswd, data.Common, data.Login, *config, data) } diff --git a/view.go b/view.go index e209565..c4d8bd4 100644 --- a/view.go +++ b/view.go @@ -5,7 +5,6 @@ package main import ( "html/template" - "log" "net/http" // "net/http" @@ -270,7 +269,6 @@ type LayoutTemplateData struct { func execTemplate(w http.ResponseWriter, t *template.Template, commonData NestedCommonTplData, loginData NestedLoginTplData, config ConfigFile, data any) error { commonData.WebsiteURL = config.WebAddress commonData.WebsiteName = config.Org - log.Printf("execTemplate %v", commonData) return t.Execute(w, LayoutTemplateData{ Common: commonData, Login: loginData,