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
|
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 {
|
func replaceIfContent(modifReq *ldap.ModifyRequest, key string, value string) error {
|
||||||
if value != "" {
|
if value != "" {
|
||||||
modifReq.Replace(key, []string{value})
|
modifReq.Replace(key, []string{value})
|
||||||
|
|
|
@ -3,8 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-ldap/ldap/v3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProfileTplData struct {
|
type ProfileTplData struct {
|
||||||
|
@ -141,8 +139,10 @@ func handlePasswd(w http.ResponseWriter, r *http.Request) {
|
||||||
} else if password2 != password {
|
} else if password2 != password {
|
||||||
data.NoMatchError = true
|
data.NoMatchError = true
|
||||||
} else {
|
} else {
|
||||||
passwordModifyRequest := ldap.NewPasswordModifyRequest(login.Info.DN, "", password)
|
err := passwd(User{
|
||||||
_, err := login.conn.PasswordModify(passwordModifyRequest)
|
DN: login.Info.DN,
|
||||||
|
Password: password,
|
||||||
|
}, config, login.conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data.ErrorMessage = err.Error()
|
data.ErrorMessage = err.Error()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue