organize_controller.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package ldap
  2. import (
  3. "errors"
  4. "nginx-ui/server/base"
  5. "nginx-ui/server/models"
  6. )
  7. type OrganizeController struct {
  8. base.Controller
  9. }
  10. // List 新增或者修改用户
  11. func (c *OrganizeController) List() {
  12. current := c.RequiredUser()
  13. if current == nil {
  14. return
  15. }
  16. organize := models.LdapOrganize{}
  17. if !c.ReadBody(&organize) {
  18. return
  19. }
  20. if organize.ServerKey == "" {
  21. server, err := ServerIns.GetServer()
  22. if err != nil {
  23. c.ErrorJson(errors.New("请先激活LDAP服务"))
  24. return
  25. }
  26. organize.ServerKey = server.Key
  27. }
  28. list, err := OrganizeIns.GetList(organize.ServerKey)
  29. if err != nil {
  30. c.ErrorJson(err)
  31. return
  32. }
  33. c.SetData(list).Json()
  34. }
  35. // Save 新增或者修改用户
  36. func (c *OrganizeController) Save() {
  37. current := c.RequiredUser()
  38. if current == nil {
  39. return
  40. }
  41. organize := models.LdapOrganize{}
  42. if !c.ReadBody(&organize) {
  43. return
  44. }
  45. if organize.ServerKey == "" {
  46. server, err := ServerIns.GetServer()
  47. if err != nil {
  48. c.ErrorJson(errors.New("请先激活LDAP服务"))
  49. return
  50. }
  51. organize.ServerKey = server.Key
  52. }
  53. resp, err := OrganizeIns.Add(&organize)
  54. if err != nil {
  55. c.ErrorJson(err)
  56. return
  57. }
  58. c.SetData(resp).Json()
  59. }
  60. func (c *OrganizeController) GetDetail() {
  61. current := c.RequiredUser()
  62. if current == nil {
  63. return
  64. }
  65. id, err := c.GetIntQuery("id")
  66. if err != nil {
  67. c.ErrorJson(err)
  68. return
  69. }
  70. resp, err := OrganizeIns.GetDetail(id)
  71. if err != nil {
  72. c.ErrorJson(err)
  73. return
  74. }
  75. c.SetData(resp).Json()
  76. }