This commit is contained in:
laodaming 2023-11-16 17:57:25 +08:00
parent 48f63db5eb
commit b21a2beff8
3 changed files with 19 additions and 4 deletions

View File

@ -3,6 +3,8 @@ package logic
import ( import (
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"fusenapi/utils/ldap_lib"
"strings"
"context" "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) { func (l *DeleteLdapUserLogic) DeleteLdapUser(req *types.DeleteLdapUserReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) req.UserDN = strings.Trim(req.UserDN, " ")
// userinfo 传入值时, 一定不为null if len(req.UserDN) <= 3 || req.UserDN[:3] != "cn=" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "无效的用户DN")
return resp.SetStatus(basic.CodeOK) }
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 必须重新处理 // 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@ -107,9 +107,11 @@ type UpdateLdapUserReq struct {
} }
type DeleteLdapUserReq struct { type DeleteLdapUserReq struct {
UserDN string `json:"user_dn"` //用户dn
} }
type GetLdapUserInfoReq struct { type GetLdapUserInfoReq struct {
UserDN string `json:"user_dn"` //用户dn
} }
type Request struct { type Request struct {

View File

@ -156,7 +156,9 @@ type UpdateLdapUserReq {
} }
//删除ldap用户 //删除ldap用户
type DeleteLdapUserReq { type DeleteLdapUserReq {
UserDN string `json:"user_dn"` //用户dn
} }
//获取ldap用户信息 //获取ldap用户信息
type GetLdapUserInfoReq { type GetLdapUserInfoReq {
UserDN string `json:"user_dn"` //用户dn
} }