74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package logic
|
|
|
|
import (
|
|
"fusenapi/utils/basic"
|
|
"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) {
|
|
|
|
if !l.svcCtx.Ldap.VerifyAuthority(r) {
|
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "无权限,请联系管理员开通")
|
|
}
|
|
req.PageCookie = strings.Trim(req.PageCookie, " ")
|
|
pageSize := uint32(20)
|
|
filter := "(objectClass=person)"
|
|
//有关键词就模糊搜索
|
|
if req.UserName != "" {
|
|
filter = "(&(objectClass=person)(sn=*" + req.UserName + "*))"
|
|
}
|
|
list, cookie, err := l.svcCtx.Ldap.GetLdapBaseTeamUserList(pageSize, filter, 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)
|
|
// }
|