package logic import ( "fusenapi/utils/basic" "fusenapi/utils/ldap_lib" "net/http" "strings" "context" "fusenapi/server/ldap-admin/internal/svc" "fusenapi/server/ldap-admin/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type GetLdapUsersLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGetLdapUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLdapUsersLogic { return &GetLdapUsersLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } // 处理进入前逻辑w,r // func (l *GetLdapUsersLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } func (l *GetLdapUsersLogic) GetLdapUsers(req *types.GetLdapUsersReq, r *http.Request) (resp *basic.Response) { ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN, l.svcCtx.Config.Ldap.PeopleGroupDN) if !ldapServer.VerifyAuthority(r.Header.Get("Ldap-Authorization"), l.svcCtx.Config.Auth.AccessSecret) { return resp.SetStatusWithMessage(basic.CodeUnAuth, "无权限,请联系管理员开通") } req.PageCookie = strings.Trim(req.PageCookie, " ") pageSize := uint32(20) list, cookie, err := ldapServer.GetLdapBaseTeamUserList(pageSize, req.PageCookie) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "查询用户列表报错,"+err.Error()) } rspList := make([]types.GetLdapUsersItem, 0, len(list)) for _, v := range list { rspList = append(rspList, types.GetLdapUsersItem{ UserId: v.UserId, UserDN: v.UserDN, UserName: v.UserName, Email: v.Email, Mobile: v.Mobile, Avatar: v.Avatar, EmployeeType: v.EmployeeType, Status: v.Status, }) } return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLdapUsersRsp{ List: rspList, PagingCookie: cookie, }) } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 // func (l *GetLdapUsersLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // }