package ldap import ( "errors" "nginx-ui/server/base" "nginx-ui/server/models" ) type OrganizeController struct { base.Controller } // List 新增或者修改用户 func (c *OrganizeController) List() { current := c.RequiredUser() if current == nil { return } organize := models.LdapOrganize{} if !c.ReadBody(&organize) { return } if organize.ServerKey == "" { server, err := ServerIns.GetServer() if err != nil { c.ErrorJson(errors.New("请先激活LDAP服务")) return } organize.ServerKey = server.Key } list, err := OrganizeIns.GetList(organize.ServerKey) if err != nil { c.ErrorJson(err) return } c.SetData(list).Json() } // Save 新增或者修改用户 func (c *OrganizeController) Save() { current := c.RequiredUser() if current == nil { return } organize := models.LdapOrganize{} if !c.ReadBody(&organize) { return } if organize.ServerKey == "" { server, err := ServerIns.GetServer() if err != nil { c.ErrorJson(errors.New("请先激活LDAP服务")) return } organize.ServerKey = server.Key } resp, err := OrganizeIns.Add(&organize) if err != nil { c.ErrorJson(err) return } c.SetData(resp).Json() } func (c *OrganizeController) GetDetail() { current := c.RequiredUser() if current == nil { return } id, err := c.GetIntQuery("id") if err != nil { c.ErrorJson(err) return } resp, err := OrganizeIns.GetDetail(id) if err != nil { c.ErrorJson(err) return } c.SetData(resp).Json() }