From 4bd314864c1cdd84e5389c4e79344f15ef2a0c22 Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Sun, 23 Jul 2023 12:00:02 +0200 Subject: [PATCH] G Pas --- gpas.go | 15 ++++++++++++++ invite.go | 20 ++++++++++++++++--- main.go | 1 + templates/lost_password_email.txt | 13 ++++++++++++ ...{lost_password.html => password_lost.html} | 0 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 templates/lost_password_email.txt rename templates/{lost_password.html => password_lost.html} (100%) diff --git a/gpas.go b/gpas.go index 8c82597..32525f6 100644 --- a/gpas.go +++ b/gpas.go @@ -19,6 +19,12 @@ import ( // "strings" ) +// type InvitationAccount struct { +// UID string +// Password string +// BaseDN string +// } + // var EMAIL_REGEXP := regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$") func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error { @@ -76,3 +82,12 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error { log.Printf("Mail sent.") return nil } + +func passwordFound(user User, config *ConfigFile, ldapConn *ldap.Conn) (bool, error) { + l := openLdap(*config) + err := l.Bind(user.DN, user.Password) + if err != nil { + return false, err + } + return true, nil +} diff --git a/invite.go b/invite.go index 9fbb3da..5a5a0d7 100644 --- a/invite.go +++ b/invite.go @@ -38,7 +38,21 @@ func checkInviterLogin(w http.ResponseWriter, r *http.Request) *LoginStatus { // New account creation directly from interface -type LostPasswordData struct { +type PasswordFoundData struct { + ErrorMessage string + Success bool + Username string + Mail string + OtherMailbox string +} + +func handleFoundPassword(w http.ResponseWriter, r *http.Request) { + templateFoundPasswordPage := getTemplate("passwd.html") + data := PasswordFoundData{} + templateFoundPasswordPage.Execute(w, data) +} + +type PasswordLostData struct { ErrorMessage string Success bool Username string @@ -47,8 +61,8 @@ type LostPasswordData struct { } func handleLostPassword(w http.ResponseWriter, r *http.Request) { - templateLostPasswordPage := getTemplate("lost_password.html") - data := LostPasswordData{} + templateLostPasswordPage := getTemplate("password_lost.html") + data := PasswordLostData{} l, err := ldapOpen(w) if err != nil { log.Printf(fmt.Sprintf("handleLostPassword : %v %v", err, l)) diff --git a/main.go b/main.go index 8db01d4..8d49fdc 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,7 @@ func main() { r.HandleFunc("/invite/new_account", handleInviteNewAccount) r.HandleFunc("/invite/send_code", handleInviteSendCode) + r.HandleFunc("/gpassword/{code}", handleFoundPassword) r.HandleFunc("/gpas", handleLostPassword) r.HandleFunc("/invitation/{code}", handleInvitationCode) diff --git a/templates/lost_password_email.txt b/templates/lost_password_email.txt new file mode 100644 index 0000000..caa3889 --- /dev/null +++ b/templates/lost_password_email.txt @@ -0,0 +1,13 @@ +From: {{.From}} +To: {{.To}} +Subject: Code d'invitation GVoisin.com +Content-type: text/plain; charset=utf-8 + +Une refonte de mot de passe avait été demandé sur GVoisin.com + +Pour créer votre compte, rendez-vous à l'addresse suivante: + +... + +À bientôt sur GVoisin.com ! + diff --git a/templates/lost_password.html b/templates/password_lost.html similarity index 100% rename from templates/lost_password.html rename to templates/password_lost.html