Refactoring

This commit is contained in:
Chris Mann 2023-07-26 13:36:10 +02:00
parent a28a4d1884
commit 385fd0b588
2 changed files with 13 additions and 12 deletions

View file

@ -138,8 +138,8 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
func passwordFound(user User, config *ConfigFile, ldapConn *ldap.Conn) (string, error) {
l, err := openLdap(config)
if err != nil {
log.Printf("passwordFound %v", err)
log.Printf("passwordFound Config : %v", config)
log.Printf("passwordFound openLdap %v", err)
// log.Printf("passwordFound openLdap Config : %v", config)
return "", err
}
if user.DN == "" && user.UID != "" {
@ -147,9 +147,9 @@ func passwordFound(user User, config *ConfigFile, ldapConn *ldap.Conn) (string,
}
err = l.Bind(user.DN, user.Password)
if err != nil {
log.Printf("passwordFound %v", err)
log.Printf("passwordFound %v", user.DN)
log.Printf("passwordFound %v", user.UID)
log.Printf("passwordFound l.Bind %v", err)
log.Printf("passwordFound l.Bind %v", user.DN)
log.Printf("passwordFound l.Bind %v", user.UID)
return "", err
}
searchReq := ldap.NewSearchRequest(user.DN, ldap.ScopeBaseObject,

View file

@ -67,21 +67,22 @@ func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
code := mux.Vars(r)["code"]
// code = strings.TrimSpace(strings.Join([]string{code}, ""))
newCode, _ := b64.URLEncoding.DecodeString(code)
ldapConn, err := openNewUserLdap(config)
ldapNewConn, err := openNewUserLdap(config)
if err != nil {
log.Printf(fmt.Sprint("handleFoundPassword / openNewUserLdap / %v", err))
log.Printf("handleFoundPassword openNewUserLdap(config) : %v", err)
data.Common.ErrorMessage = err.Error()
}
codeArray := strings.Split(string(newCode), ";")
user := User{
UID: codeArray[0],
Password: codeArray[1],
DN: "uid=" + codeArray[0] + ",ou=invitations,dc=resdigita,dc=org",
DN: "uid=" + codeArray[0] + "," + config.InvitationBaseDN,
}
user.SeeAlso, err = passwordFound(user, config, ldapConn)
user.SeeAlso, err = passwordFound(user, config, ldapNewConn)
if err != nil {
log.Printf("handleFoundPassword / passwordFound %v", err)
log.Printf("handleFoundPassword / passwordFound %v", err)
log.Printf("passwordFound(user, config, ldapConn) %v", err)
log.Printf("passwordFound(user, config, ldapConn) %v", user)
log.Printf("passwordFound(user, config, ldapConn) %v", ldapNewConn)
data.Common.ErrorMessage = err.Error()
}
if r.Method == "POST" {
@ -98,7 +99,7 @@ func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
err := passwd(User{
DN: user.SeeAlso,
Password: password,
}, config, ldapConn)
}, config, ldapNewConn)
if err != nil {
data.Common.ErrorMessage = err.Error()
} else {