Refactor Site-Wide Data
This commit is contained in:
parent
887954d506
commit
bf2d515ad2
|
@ -11,10 +11,10 @@
|
||||||
<h2>S'identifier</h2>
|
<h2>S'identifier</h2>
|
||||||
|
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
{{if .WrongUser}}
|
{{if .DataWrongUser}}
|
||||||
<div class="alert alert-danger">Identifiant invalide.</div>
|
<div class="alert alert-danger">Identifiant invalide.</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .WrongPass}}
|
{{if .DataWrongPass}}
|
||||||
<div class="alert alert-danger">Mot de passe invalide.</div>
|
<div class="alert alert-danger">Mot de passe invalide.</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .Common.ErrorMessage}}
|
{{if .Common.ErrorMessage}}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<label for="password">Nouveau mot de passe :</label>
|
<label for="password">Nouveau mot de passe :</label>
|
||||||
<input type="password" id="password" name="password" class="form-control" minlength="8" required />
|
<input type="password" id="password" name="password" class="form-control" minlength="8" required />
|
||||||
</div>
|
</div>
|
||||||
{{if .TooShortError}}
|
{if .DataTooShortError}}
|
||||||
<div class="alert alert-warning">
|
<div class="alert alert-warning">
|
||||||
Le mot de passe choisi est trop court (minimum 8 caractères).
|
Le mot de passe choisi est trop court (minimum 8 caractères).
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
<label for="password2">Répéter le mot de passe :</label>
|
<label for="password2">Répéter le mot de passe :</label>
|
||||||
<input type="password" id="password2" name="password2" class="form-control" />
|
<input type="password" id="password2" name="password2" class="form-control" />
|
||||||
</div>
|
</div>
|
||||||
{{if .NoMatchError}}
|
{if .DataNoMatchError}}
|
||||||
<div class="alert alert-warning">
|
<div class="alert alert-warning">
|
||||||
Les deux mots de passe entrés ne correspondent pas.
|
Les deux mots de passe entrés ne correspondent pas.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -73,17 +73,26 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
|
||||||
log.Printf("%v", username)
|
log.Printf("%v", username)
|
||||||
data.Common.ErrorMessage = err.Error()
|
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)
|
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||||
return loginInfo
|
return loginInfo
|
||||||
|
|
||||||
} else if r.Method == "GET" {
|
} else if r.Method == "GET" {
|
||||||
templateLogin.Execute(w, LoginFormData{
|
execTemplate(w, templateLogin, NestedCommonTplData{
|
||||||
|
CanAdmin: false,
|
||||||
|
CanInvite: true,
|
||||||
|
LoggedIn: false}, NestedLoginTplData{}, *config, LoginFormData{
|
||||||
Common: NestedCommonTplData{
|
Common: NestedCommonTplData{
|
||||||
CanAdmin: false,
|
CanAdmin: false,
|
||||||
CanInvite: true,
|
CanInvite: true,
|
||||||
LoggedIn: false}})
|
LoggedIn: false}})
|
||||||
|
// templateLogin.Execute(w, LoginFormData{
|
||||||
|
// Common: NestedCommonTplData{
|
||||||
|
// CanAdmin: false,
|
||||||
|
// CanInvite: true,
|
||||||
|
// LoggedIn: false}})
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "Unsupported method", http.StatusBadRequest)
|
http.Error(w, "Unsupported method", http.StatusBadRequest)
|
||||||
|
|
|
@ -54,7 +54,8 @@ func handleLostPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
err = passwordLost(user, config, ldapNewConn)
|
err = passwordLost(user, config, ldapNewConn)
|
||||||
}
|
}
|
||||||
data.Common.CanAdmin = false
|
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) {
|
func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -108,7 +109,8 @@ func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.Common.CanAdmin = false
|
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) {
|
func handlePasswd(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -153,5 +155,6 @@ func handlePasswd(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.Common.CanAdmin = false
|
data.Common.CanAdmin = false
|
||||||
templatePasswd.Execute(w, data)
|
// templatePasswd.Execute(w, data)
|
||||||
|
execTemplate(w, templatePasswd, data.Common, data.Login, *config, data)
|
||||||
}
|
}
|
||||||
|
|
2
view.go
2
view.go
|
@ -5,7 +5,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
// "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 {
|
func execTemplate(w http.ResponseWriter, t *template.Template, commonData NestedCommonTplData, loginData NestedLoginTplData, config ConfigFile, data any) error {
|
||||||
commonData.WebsiteURL = config.WebAddress
|
commonData.WebsiteURL = config.WebAddress
|
||||||
commonData.WebsiteName = config.Org
|
commonData.WebsiteName = config.Org
|
||||||
log.Printf("execTemplate %v", commonData)
|
|
||||||
return t.Execute(w, LayoutTemplateData{
|
return t.Execute(w, LayoutTemplateData{
|
||||||
Common: commonData,
|
Common: commonData,
|
||||||
Login: loginData,
|
Login: loginData,
|
||||||
|
|
Loading…
Reference in a new issue