Factoring the model user and correcting password
This commit is contained in:
parent
95674722e5
commit
0f349fc70d
2 changed files with 10 additions and 4 deletions
|
@ -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})
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue