From 54e68b9fe373ec842487c1c504f9e9acf3b2d1cf Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Fri, 21 Jul 2023 09:51:57 +0200 Subject: [PATCH] Implementing Activate User --- invite.go | 9 ++++++--- utils.go | 17 ++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/invite.go b/invite.go index 39c3499..9bab204 100644 --- a/invite.go +++ b/invite.go @@ -38,12 +38,15 @@ func checkInviterLogin(w http.ResponseWriter, r *http.Request) *LoginStatus { // New account creation directly from interface func handleInviteNewAccount(w http.ResponseWriter, r *http.Request) { + l := ldapOpen(w) + l.Bind(config.NewUserDN, config.NewUserPassword) + // login := checkInviterLogin(w, r) // if login == nil { // return // } - l, _ := ldap.DialURL(config.LdapServerAddr) - l.Bind(config.NewUserDN, config.NewUserPassword) + // l, _ := ldap.DialURL(config.LdapServerAddr) + // l.Bind(config.NewUserDN, config.NewUserPassword) handleNewAccount(w, r, l, config.NewUserDN) } @@ -143,7 +146,7 @@ func handleNewAccount(w http.ResponseWriter, r *http.Request, l *ldap.Conn, invi data.ErrorPasswordMismatch = true } else { newUser.Password = password2 - data.Success = addNewUser(newUser, config) + data.Success = addNewUser(newUser, config, l) http.Redirect(w, r, "/admin/ldap/"+newUser.DN, http.StatusFound) } diff --git a/utils.go b/utils.go index f8fe189..6501663 100644 --- a/utils.go +++ b/utils.go @@ -1,7 +1,6 @@ package main import ( - "crypto/tls" "fmt" "log" @@ -41,14 +40,14 @@ func suggestPassword() string { return password } -func addNewUser(newUser NewUser, config *ConfigFile) bool { +func addNewUser(newUser NewUser, config *ConfigFile, ldapConn *ldap.Conn) bool { log.Printf(fmt.Sprint("Adding New User")) - l, _ := ldap.DialURL(config.LdapServerAddr) - err := l.StartTLS(&tls.Config{InsecureSkipVerify: true}) - if err != nil { - log.Printf(fmt.Sprintf("86: %v", err)) - } - l.Bind(config.NewUserDN, config.NewUserPassword) + // l, _ := ldap.DialURL(config.LdapServerAddr) + // l.Bind(config.NewUserDN, config.NewUserPassword) + // err := l.StartTLS(&tls.Config{InsecureSkipVerify: true}) + // if err != nil { + // log.Printf(fmt.Sprintf("86: %v", err)) + // } // l.Bind(config.) dn := newUser.DN @@ -82,7 +81,7 @@ func addNewUser(newUser NewUser, config *ConfigFile) bool { // conn := - err = l.Add(req) + err := ldapConn.Add(req) log.Printf(fmt.Sprintf("71: %v", err)) log.Printf(fmt.Sprintf("72: %v", req)) log.Printf(fmt.Sprintf("73: %v", newUser))