Factoring the model user and correcting password

This commit is contained in:
Chris Mann 2023-07-22 10:18:05 +02:00
parent 0153f8acec
commit 5b9168fd1a
2 changed files with 7 additions and 11 deletions

View file

@ -231,21 +231,21 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
templateLogin.Execute(w, LoginFormData{})
return nil
} else if r.Method == "POST" {
log.Printf("%v", "Parsing Form handleLogin")
// log.Printf("%v", "Parsing Form handleLogin")
r.ParseForm()
username := strings.Join(r.Form["username"], "")
password := strings.Join(r.Form["password"], "")
user_dn := fmt.Sprintf("%s=%s,%s", config.UserNameAttr, username, config.UserBaseDN)
log.Printf("%v", user_dn)
log.Printf("%v", username)
// log.Printf("%v", user_dn)
// log.Printf("%v", username)
if strings.EqualFold(username, config.AdminAccount) {
user_dn = username
}
loginInfo, err := doLogin(w, r, username, user_dn, password)
log.Printf("%v", loginInfo)
// log.Printf("%v", loginInfo)
if err != nil {
data := &LoginFormData{
Username: username,
@ -275,8 +275,8 @@ func doLogin(w http.ResponseWriter, r *http.Request, username string, user_dn st
err := l.Bind(user_dn, password)
if err != nil {
log.Printf("%v", err)
log.Printf("%v", user_dn)
log.Printf("doLogin : %v", err)
log.Printf("doLogin : %v", user_dn)
return nil, err
}
@ -292,7 +292,7 @@ func doLogin(w http.ResponseWriter, r *http.Request, username string, user_dn st
err = session.Save(r, w)
if err != nil {
log.Printf("%v", err)
log.Printf("doLogin Session Save: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return nil, err
}

View file

@ -135,7 +135,6 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
}
func modify(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
log.Printf("Modify User : %v", user)
modify_request := ldap.NewModifyRequest(user.DN, nil)
previousUser, err := get(user, config, ldapConn)
if err != nil {
@ -169,9 +168,6 @@ func replaceIfContent(modifReq *ldap.ModifyRequest, key string, value string, pr
if value != "" {
modifReq.Replace(key, []string{value})
} else if previousValue != "" {
log.Printf("modify User delete %v", key)
log.Printf("modify User delete %v", value)
log.Printf("modify User delete %v", previousValue)
modifReq.Delete(key, []string{previousValue})
}
return nil