Refactoring

This commit is contained in:
Chris Mann 2023-07-26 13:16:41 +02:00
parent 7f3383944b
commit 3cee5a3745
2 changed files with 11 additions and 8 deletions

View file

@ -46,9 +46,10 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
searchReq := ldap.NewSearchRequest(config.UserBaseDN, ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false, searchFilter, []string{"cn", "uid", "mail", "carLicense", "sn", "displayName", "givenName"}, nil)
searchRes, err := ldapConn.Search(searchReq)
if err != nil {
log.Printf(fmt.Sprintf("passwordLost 49 : %v %v", err, ldapConn))
log.Printf(fmt.Sprintf("passwordLost 50 : %v", searchReq))
log.Printf(fmt.Sprintf("passwordLost 51: %v", user))
log.Printf(fmt.Sprintf("passwordLost search : %v %v", err, ldapConn))
log.Printf(fmt.Sprintf("passwordLost search : %v", searchReq))
log.Printf(fmt.Sprintf("passwordLost search : %v", searchRes))
log.Printf(fmt.Sprintf("passwordLost search: %v", user))
return err
}
if len(searchRes.Entries) == 0 {

View file

@ -7,6 +7,7 @@ import (
"net/http"
"strings"
"github.com/go-ldap/ldap/v3"
"github.com/gorilla/mux"
)
@ -33,23 +34,24 @@ func handleLostPassword(w http.ResponseWriter, r *http.Request) {
Mail: strings.TrimSpace(strings.Join(r.Form["mail"], "")),
OtherMailbox: strings.TrimSpace(strings.Join(r.Form["othermailbox"], "")),
}
ldapConn, err := openNewUserLdap(config)
ldapNewConn, err := openNewUserLdap(config)
if err != nil {
log.Printf(fmt.Sprintf("handleLostPassword 99 : %v %v", err, ldapConn))
log.Printf(fmt.Sprintf("handleLostPassword 99 : %v %v", err, ldapNewConn))
data.Common.ErrorMessage = err.Error()
}
if err != nil {
log.Printf(fmt.Sprintf("handleLostPassword 104 : %v %v", err, ldapConn))
log.Printf(fmt.Sprintf("handleLostPassword 104 : %v %v", err, ldapNewConn))
data.Common.ErrorMessage = err.Error()
} else {
err = ldapConn.Bind(config.NewUserDN, config.NewUserPassword)
// err = ldapConn.Bind(config.NewUserDN, config.NewUserPassword)
if err != nil {
log.Printf(fmt.Sprintf("handleLostPassword 109 : %v %v", err, ldapConn))
log.Printf(fmt.Sprintf("handleLostPassword 109 : %v %v", err, ldapNewConn))
data.Common.ErrorMessage = err.Error()
} else {
data.Common.Success = true
}
}
err = passwordLost(user, config, ldapNewConn)
}
data.Common.CanAdmin = false
templateLostPasswordPage.Execute(w, data)