Fixed Change Password Bug

This commit is contained in:
Chris Mann 2023-07-25 15:01:20 +02:00
parent 020dc0f6d4
commit 6033c90d96

View file

@ -10,7 +10,10 @@ import (
func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus { func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
var login_info *LoginInfo var login_info *LoginInfo
l, err := ldapOpen(w)
if l == nil {
return nil
}
session, err := store.Get(r, SESSION_NAME) session, err := store.Get(r, SESSION_NAME)
if err == nil { if err == nil {
username, ok := session.Values["login_username"] username, ok := session.Values["login_username"]
@ -23,28 +26,16 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
Username: username.(string), Username: username.(string),
Password: password.(string), Password: password.(string),
} }
} else {
return nil
}
}
l, err := ldapOpen(w)
if l == nil {
return nil
}
if err != nil { if err != nil {
log.Printf("checkLogin ldapOpen : %v", err) log.Printf("checkLogin ldapOpen : %v", err)
log.Printf("checkLogin ldapOpen : %v", session) log.Printf("checkLogin ldapOpen : %v", session)
log.Printf("checkLogin ldapOpen : %v", session.Values) log.Printf("checkLogin ldapOpen : %v", session.Values)
return nil return nil
} }
err = bind(User{ err = bind(User{
DN: login_info.DN, DN: login_info.DN,
Password: login_info.Password, Password: login_info.Password,
}, config, l) }, config, l)
if err != nil { if err != nil {
delete(session.Values, "login_username") delete(session.Values, "login_username")
delete(session.Values, "login_password") delete(session.Values, "login_password")
@ -57,19 +48,17 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
} }
return checkLogin(w, r) return checkLogin(w, r)
} }
}
}
ldapUser, err := get(User{ ldapUser, err := get(User{
DN: login_info.DN, DN: login_info.DN,
CN: login_info.Username, CN: login_info.Username,
}, config, l) }, config, l)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return nil return nil
} }
userEntry := ldapUser.UserEntry userEntry := ldapUser.UserEntry
loginStatus := &LoginStatus{ loginStatus := &LoginStatus{
Info: login_info, Info: login_info,
conn: l, conn: l,
@ -77,6 +66,8 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
CanAdmin: ldapUser.CanAdmin, CanAdmin: ldapUser.CanAdmin,
CanInvite: ldapUser.CanInvite, CanInvite: ldapUser.CanInvite,
} }
return loginStatus
}
/* /*
@ -165,9 +156,6 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
return loginStatus return loginStatus
*/ */
return loginStatus
}
func logout(w http.ResponseWriter, r *http.Request) error { func logout(w http.ResponseWriter, r *http.Request) error {
session, err := store.Get(r, SESSION_NAME) session, err := store.Get(r, SESSION_NAME)
if err != nil { if err != nil {