12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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()
- }
|