feat: LDAP user can reset password with old password and new password (#3516)

* feat: support user reset password with old password and new password

* feat: merge similar code
This commit is contained in:
DacongDA 2025-01-20 21:42:05 +08:00 committed by GitHub
parent 18b49bb731
commit db551eb24a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 3 deletions

View File

@ -574,7 +574,11 @@ func (c *ApiController) SetPassword() {
if user.Ldap == "" {
_, err = object.UpdateUser(userId, targetUser, []string{"password", "need_update_password", "password_type", "last_change_password_time"}, false)
} else {
err = object.ResetLdapPassword(targetUser, newPassword, c.GetAcceptLanguage())
if isAdmin {
err = object.ResetLdapPassword(targetUser, "", newPassword, c.GetAcceptLanguage())
} else {
err = object.ResetLdapPassword(targetUser, oldPassword, newPassword, c.GetAcceptLanguage())
}
}
if err != nil {

View File

@ -375,7 +375,7 @@ func GetExistUuids(owner string, uuids []string) ([]string, error) {
return existUuids, nil
}
func ResetLdapPassword(user *User, newPassword string, lang string) error {
func ResetLdapPassword(user *User, oldPassword string, newPassword string, lang string) error {
ldaps, err := GetLdaps(user.Owner)
if err != nil {
return err
@ -418,6 +418,15 @@ func ResetLdapPassword(user *User, newPassword string, lang string) error {
}
modifyPasswordRequest.Replace("unicodePwd", []string{pwdEncoded})
modifyPasswordRequest.Replace("userAccountControl", []string{"512"})
} else if oldPassword != "" {
modifyPasswordRequestWithOldPassword := goldap.NewPasswordModifyRequest(userDn, oldPassword, newPassword)
_, err = conn.Conn.PasswordModify(modifyPasswordRequestWithOldPassword)
if err != nil {
conn.Close()
return err
}
conn.Close()
return nil
} else {
switch ldapServer.PasswordType {
case "SSHA":

View File

@ -105,7 +105,7 @@ export const PasswordModal = (props) => {
});
};
const hasOldPassword = user.password !== "";
const hasOldPassword = (user.password !== "" || user.ldap !== "");
return (
<Row>