Factoring the model user and correcting password
This commit is contained in:
parent
0b86dc9e0e
commit
0e4525716e
1 changed files with 12 additions and 6 deletions
|
@ -134,11 +134,15 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
|
|
||||||
func modify(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
func modify(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
modify_request := ldap.NewModifyRequest(user.DN, nil)
|
modify_request := ldap.NewModifyRequest(user.DN, nil)
|
||||||
replaceIfContent(modify_request, "displayName", user.DisplayName)
|
previousUser, err := get(user, config, ldapConn)
|
||||||
replaceIfContent(modify_request, "givenName", user.GivenName)
|
if err != nil {
|
||||||
replaceIfContent(modify_request, "sn", user.SN)
|
return err
|
||||||
replaceIfContent(modify_request, "description", user.Description)
|
}
|
||||||
err := ldapConn.Modify(modify_request)
|
replaceIfContent(modify_request, "displayName", user.DisplayName, previousUser.DisplayName)
|
||||||
|
replaceIfContent(modify_request, "givenName", user.GivenName, previousUser.GivenName)
|
||||||
|
replaceIfContent(modify_request, "sn", user.SN, previousUser.SN)
|
||||||
|
replaceIfContent(modify_request, "description", user.Description, previousUser.Description)
|
||||||
|
err = ldapConn.Modify(modify_request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -155,9 +159,11 @@ func bind(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
return ldapConn.Bind(user.DN, user.Password)
|
return ldapConn.Bind(user.DN, user.Password)
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceIfContent(modifReq *ldap.ModifyRequest, key string, value string) error {
|
func replaceIfContent(modifReq *ldap.ModifyRequest, key string, value string, previousValue string) error {
|
||||||
if value != "" {
|
if value != "" {
|
||||||
modifReq.Replace(key, []string{value})
|
modifReq.Replace(key, []string{value})
|
||||||
|
} else {
|
||||||
|
modifReq.Delete(key, []string{value})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue