Refactor Site-Wide Data

This commit is contained in:
Chris Mann 2023-07-27 15:57:17 +02:00
parent 887954d506
commit bf2d515ad2
5 changed files with 21 additions and 11 deletions

View file

@ -11,10 +11,10 @@
<h2>S'identifier</h2>
<form method="POST">
{{if .WrongUser}}
{{if .DataWrongUser}}
<div class="alert alert-danger">Identifiant invalide.</div>
{{end}}
{{if .WrongPass}}
{{if .DataWrongPass}}
<div class="alert alert-danger">Mot de passe invalide.</div>
{{end}}
{{if .Common.ErrorMessage}}

View file

@ -23,7 +23,7 @@
<label for="password">Nouveau mot de passe :</label>
<input type="password" id="password" name="password" class="form-control" minlength="8" required />
</div>
{{if .TooShortError}}
{if .DataTooShortError}}
<div class="alert alert-warning">
Le mot de passe choisi est trop court (minimum 8 caractères).
</div>
@ -32,7 +32,7 @@
<label for="password2">Répéter le mot de passe :</label>
<input type="password" id="password2" name="password2" class="form-control" />
</div>
{{if .NoMatchError}}
{if .DataNoMatchError}}
<div class="alert alert-warning">
Les deux mots de passe entrés ne correspondent pas.
</div>

View file

@ -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)

View file

@ -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)
}

View file

@ -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,