Factoring the model user and correcting password

This commit is contained in:
Chris Mann 2023-07-22 07:43:41 +02:00
parent 95674722e5
commit 0f349fc70d
2 changed files with 10 additions and 4 deletions

View file

@ -92,6 +92,12 @@ func modify(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
return nil
}
func passwd(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
passwordModifyRequest := ldap.NewPasswordModifyRequest(user.DN, "", user.Password)
_, err := ldapConn.PasswordModify(passwordModifyRequest)
return err
}
func replaceIfContent(modifReq *ldap.ModifyRequest, key string, value string) error {
if value != "" {
modifReq.Replace(key, []string{value})

View file

@ -3,8 +3,6 @@ package main
import (
"net/http"
"strings"
"github.com/go-ldap/ldap/v3"
)
type ProfileTplData struct {
@ -141,8 +139,10 @@ func handlePasswd(w http.ResponseWriter, r *http.Request) {
} else if password2 != password {
data.NoMatchError = true
} else {
passwordModifyRequest := ldap.NewPasswordModifyRequest(login.Info.DN, "", password)
_, err := login.conn.PasswordModify(passwordModifyRequest)
err := passwd(User{
DN: login.Info.DN,
Password: password,
}, config, login.conn)
if err != nil {
data.ErrorMessage = err.Error()
} else {