Refactor Site-Wide Data
This commit is contained in:
parent
a1ef0d09d1
commit
768ef0d836
4 changed files with 29 additions and 3 deletions
|
@ -19,7 +19,7 @@
|
|||
|
||||
<body>
|
||||
<div class="container mb-4">
|
||||
<h1><a href="/">GVoisins.org > {{ template "title" .}}</a></h1>
|
||||
<h1><a href="/">App.LesGrandsVoisins.Com > {{ template "title" .}}</a></h1>
|
||||
<nav role="navigation">
|
||||
<div id="menuToggle">
|
||||
<!--
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
Nouveau mot de passe enregistré.
|
||||
</div>
|
||||
{{else}}
|
||||
<form method="POST" class="mt-4" onsubmit="javascript:var password = document.getElementById('password');var password2 = document.getElementById('password2'); if (password.value != password.value) {alert('Les maux de passe ne sont pas identiques entre l\'initial et la confirmation.');return false;}; message = checkPasswordStrength(password.value); if (message) {alert(message);return false}else{return true;}">
|
||||
<form method="POST" class="mt-4" onsubmit="javascript:var password = document.getElementById('password');var password2 = document.getElementById('password2'); if (password.value != password2.value) {alert('Les maux de passe ne sont pas identiques entre l\'initial et la confirmation.');return false;}; message = checkPasswordStrength(password.value); if (message) {alert(message);return false}else{return true;}">
|
||||
<div class="form-group">
|
||||
<label for="password">Nouveau mot de passe :</label>
|
||||
<input type="password" id="password" name="password" class="form-control" minlength="8" required />
|
||||
|
|
|
@ -35,6 +35,7 @@ func handleHome(w http.ResponseWriter, r *http.Request) {
|
|||
LoggedIn: true,
|
||||
},
|
||||
}
|
||||
templateHome.Execute(w, data)
|
||||
execTemplate(w, templateHome, &data.Common, &data.Login, *config, data)
|
||||
// templateHome.Execute(w, data)
|
||||
|
||||
}
|
||||
|
|
25
view.go
25
view.go
|
@ -5,6 +5,9 @@ package main
|
|||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
// "net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
|
@ -18,6 +21,8 @@ type NestedCommonTplData struct {
|
|||
LoggedIn bool
|
||||
Success bool
|
||||
WarningMessage string
|
||||
WebsiteName string
|
||||
WebsiteURL string
|
||||
}
|
||||
type NestedLoginTplData struct {
|
||||
Login *LoginStatus
|
||||
|
@ -240,6 +245,10 @@ type SendMailTplData struct {
|
|||
EmailContentVars EmailContentVarsTplData
|
||||
}
|
||||
|
||||
type WrapperTemplate struct {
|
||||
Template *template.Template
|
||||
}
|
||||
|
||||
var templatePath = "./templates"
|
||||
|
||||
func getTemplate(name string) *template.Template {
|
||||
|
@ -250,3 +259,19 @@ func getTemplate(name string) *template.Template {
|
|||
templatePath+"/"+name,
|
||||
))
|
||||
}
|
||||
|
||||
type LayoutTemplateData struct {
|
||||
Common NestedCommonTplData
|
||||
Login NestedLoginTplData
|
||||
Data any
|
||||
}
|
||||
|
||||
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
|
||||
return t.Execute(w, LayoutTemplateData{
|
||||
Common: *commonData,
|
||||
Login: *loginData,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue