diff --git a/server/ldap-admin/internal/logic/deleteldapuserlogic.go b/server/ldap-admin/internal/logic/deleteldapuserlogic.go index 96f8897d..fa18e505 100644 --- a/server/ldap-admin/internal/logic/deleteldapuserlogic.go +++ b/server/ldap-admin/internal/logic/deleteldapuserlogic.go @@ -3,6 +3,8 @@ package logic import ( "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/ldap_lib" + "strings" "context" @@ -31,10 +33,19 @@ func NewDeleteLdapUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *De // } func (l *DeleteLdapUserLogic) DeleteLdapUser(req *types.DeleteLdapUserReq, 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, " ") + if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN") + } + 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{ + "postalCode": {"0"}, + }) + 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 eb6c55f4..7310bd74 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -107,9 +107,11 @@ type UpdateLdapUserReq struct { } type DeleteLdapUserReq struct { + UserDN string `json:"user_dn"` //用户dn } type GetLdapUserInfoReq struct { + UserDN string `json:"user_dn"` //用户dn } type Request struct { diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index c627e81a..6261a2ab 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -156,7 +156,9 @@ type UpdateLdapUserReq { } //删除ldap用户 type DeleteLdapUserReq { + UserDN string `json:"user_dn"` //用户dn } //获取ldap用户信息 type GetLdapUserInfoReq { + UserDN string `json:"user_dn"` //用户dn } \ No newline at end of file