From 8505abca6f092beb7c30278c4bc9ab265fb9f8dd Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Wed, 26 Jul 2023 11:05:47 +0200 Subject: [PATCH] Refactoring --- controller.go | 1 + model-user.go | 10 +++++----- templates/user/mail.txt | 2 +- templates/user/new.email.txt | 13 +++++++++++++ templates/user/wait.html | 26 ++++++++++++++++++++++++++ view-user.go | 5 +++++ view.go | 8 +++++++- 7 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 templates/user/new.email.txt create mode 100644 templates/user/wait.html diff --git a/controller.go b/controller.go index 03b3119..93fef1c 100644 --- a/controller.go +++ b/controller.go @@ -67,6 +67,7 @@ func makeGVRouter() (*mux.Router, error) { r.HandleFunc("/user", handleUser) r.HandleFunc("/user/new", handleInviteNewAccount) + r.HandleFunc("/user/wait", handleUserWait) r.HandleFunc("/picture/{name}", handleDownloadPicture) diff --git a/model-user.go b/model-user.go index 6c22903..51d3051 100644 --- a/model-user.go +++ b/model-user.go @@ -121,11 +121,11 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error { sendMailTplData := SendMailTplData{ From: "alice@resdigita.org", To: user.OtherMailbox, - RelTemplatePath: "user/mail.txt", - ContentVars: map[string]string{ - "InviteFrom": "alice@resdigita.org", - "SebAddress": "https://www.gvoisins.org", - "Code": "...", + RelTemplatePath: "user/new.email.txt", + EmailContentVars: EmailContentVarsTplData{ + InviteFrom: "alice@resdigita.org", + SendAddress: "https://www.gvoisins.org", + Code: "...", }, } err = sendMail(sendMailTplData) diff --git a/templates/user/mail.txt b/templates/user/mail.txt index 6058937..6e79e60 100644 --- a/templates/user/mail.txt +++ b/templates/user/mail.txt @@ -5,7 +5,7 @@ Content-type: text/plain; charset=utf-8 Vous avez été invité à créer un compte sur GVoisin.com par {{.InviteFrom}} :) -Pour créer votre compte, rendez-vous à l'addresse suivante: +Pour créer votre compte, rendez-vous à l'adresse suivante: {{.WebBaseAddress}}/invitation/{{.Code}} diff --git a/templates/user/new.email.txt b/templates/user/new.email.txt new file mode 100644 index 0000000..f2d75b8 --- /dev/null +++ b/templates/user/new.email.txt @@ -0,0 +1,13 @@ +From: {{.From}} +To: {{.To}} +Subject: Code d'invitation GVoisin.com +Content-type: text/plain; charset=utf-8 + +Vous avez été invité à créer un compte sur GVoisin.com par {{.InviteFrom}} :) + +Pour créer votre compte, rendez-vous à l'adresse suivante: + +{{.WebBaseAddress}}/invitation/{{.Code}} + +À bientôt sur GVoisin.com ! + diff --git a/templates/user/wait.html b/templates/user/wait.html new file mode 100644 index 0000000..dc5bbbe --- /dev/null +++ b/templates/user/wait.html @@ -0,0 +1,26 @@ +{{define "title"}}Attente de validation{{end}} + +{{define "admenu"}} +{{end}} + +{{define "body"}} +{{if .Common.ErrorMessage}} +
Impossible de créer le compte. +
{{ .Common.ErrorMessage }}
+
+{{end}} +{{if .Common.WarningMessage}} +
Des erreurs se sont produites, le compte pourrait ne pas être totalement + fonctionnel. +
{{ .Common.WarningMessage }}
+
+{{end}} +{{if .Common.Success}} +
+ Le compe a été créé ! + Rendez-vous sur la page d'accueil pour vous connecter avec ce nouveau compte. +
+{{else}} +

Vous avez reçu un courriel. Nous allons valider votre compte.

+{{end}} +{{end}} \ No newline at end of file diff --git a/view-user.go b/view-user.go index eb662a8..be1a748 100644 --- a/view-user.go +++ b/view-user.go @@ -9,6 +9,11 @@ import ( // "github.com/gorilla/mux" ) +func handleUserWait(w http.ResponseWriter, r *http.Request) { + templateProfile := getTemplate("user/wait.html") + templateProfile.Execute(w, nil) +} + func handleUser(w http.ResponseWriter, r *http.Request) { templateProfile := getTemplate("user.html") diff --git a/view.go b/view.go index f217d52..23c9ea5 100644 --- a/view.go +++ b/view.go @@ -218,6 +218,12 @@ type LoginFormData struct { Common NestedCommonTplData } +type EmailContentVarsTplData struct { + Code string + SendAddress string + InviteFrom string +} + // Data to be passed to an email for sending type SendMailTplData struct { // Sender of the email @@ -228,7 +234,7 @@ type SendMailTplData struct { // usually ending in .txt RelTemplatePath string // Variables to be included in the template of the email - ContentVars map[string]string + EmailContentVars EmailContentVarsTplData } var templatePath = "./templates"