diff --git a/server/ldap-admin/internal/logic/updateldapuserlogic.go b/server/ldap-admin/internal/logic/updateldapuserlogic.go index c4b61f1d..490fee69 100644 --- a/server/ldap-admin/internal/logic/updateldapuserlogic.go +++ b/server/ldap-admin/internal/logic/updateldapuserlogic.go @@ -1,8 +1,12 @@ package logic import ( + "fmt" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/chinese_to_pinyin" + "fusenapi/utils/ldap_lib" + "strings" "context" @@ -31,10 +35,34 @@ func NewUpdateLdapUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up // } func (l *UpdateLdapUserLogic) UpdateLdapUser(req *types.UpdateLdapUserReq, userinfo *auth.UserInfo) (resp *basic.Response) { - // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) - // userinfo 传入值时, 一定不为null - - return resp.SetStatus(basic.CodeOK) + req.UserDN = strings.Trim(req.UserDN, " ") + req.Mobile = strings.Trim(req.Mobile, " ") + req.Password = strings.Trim(req.Password, " ") + req.Avatar = strings.Trim(req.Avatar, " ") + req.UserName = strings.Trim(req.UserName, " ") + if req.Password != "" { + //todo 验证下是不是本人 + } + if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN") + } + //把用户名转pinyin + userNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.UserName) + ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) + err := ldapServer.Update(req.UserDN, map[string][]string{ + "homeDirectory": {"/home/users/" + userNamePinyin}, + "sn": {req.UserName}, + "uid": {userNamePinyin}, + "mobile": {req.Mobile}, + "userPassword": {req.Password}, + "postalAddress": {req.Avatar}, + "postalCode": {fmt.Sprintf("%d", req.Status)}, + }) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "更新用户失败,", err.Error()) + } + return resp.SetStatusWithMessage(basic.CodeOK, "更新用户成功") } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index 02f84a97..eb6c55f4 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -98,6 +98,12 @@ type CreateLdapUserReq struct { } type UpdateLdapUserReq struct { + UserDN string `json:"user_dn"` //用户dn + UserName string `json:"user_name"` //用户名 + Password string `json:"password,optional"` //密码 + Mobile string `json:"mobile,optional"` //手机号 + Avatar string `json:"avatar,optional"` //头像地址 + Status int64 `json:"status,options=0|1"` //状态 1正常0离职 } type DeleteLdapUserReq struct { diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index 700cefb3..c627e81a 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -147,6 +147,12 @@ type CreateLdapUserReq { } //修改ldap用户信息 type UpdateLdapUserReq { + UserDN string `json:"user_dn"` //用户dn + UserName string `json:"user_name"` //用户名 + Password string `json:"password,optional"` //密码 + Mobile string `json:"mobile,optional"` //手机号 + Avatar string `json:"avatar,optional"` //头像地址 + Status int64 `json:"status,options=0|1"` //状态 1正常0离职 } //删除ldap用户 type DeleteLdapUserReq {