user_controller.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package ldap
  2. import (
  3. "nginx-ui/server/base"
  4. "nginx-ui/server/models"
  5. )
  6. type UserController struct {
  7. base.Controller
  8. }
  9. func (c *UserController) Login() {
  10. req := LDAPLoginReq{}
  11. if c.ReadBody(&req) == false {
  12. return
  13. }
  14. user, err := ServiceInstance.Login(&req)
  15. if err != nil {
  16. c.ErrorJson(err)
  17. return
  18. }
  19. user.Password = ""
  20. c.SetSession("user", *user)
  21. c.PostJson(models.SuccessResp(user))
  22. }
  23. // SyncUsers 同步用户信息
  24. // post /ldap/user/sync
  25. func (c *UserController) SyncUsers() {
  26. current := c.RequiredUser()
  27. if current == nil {
  28. return
  29. }
  30. req := LDAPUserSyncReq{}
  31. if !c.ReadBody(&req) {
  32. return
  33. }
  34. count, err := ServiceInstance.SyncUsers(current, &req)
  35. if err != nil {
  36. c.ErrorJson(err)
  37. return
  38. }
  39. resp := make(map[string]interface{})
  40. resp["count"] = count
  41. c.SetData(resp).Json()
  42. }
  43. // UpdateUserPassword 更新用户密码
  44. // post /ldap/user/modifyPassword
  45. func (c *UserController) UpdateUserPassword() {
  46. }
  47. // UpdateUser 更新用户信息或者新增用户
  48. // post /ldap/user/save
  49. func (c *UserController) UpdateUser() {
  50. }
  51. // GetUsers 获取全部用户
  52. // get /ldap/users
  53. func (c *UserController) GetUsers() {
  54. current := c.RequiredUser()
  55. if current == nil {
  56. return
  57. }
  58. req := UserListReq{}
  59. if !c.ReadBody(&req) {
  60. return
  61. }
  62. resp, err := ServiceInstance.GetUsers(current, &req)
  63. if err != nil {
  64. c.ErrorJson(err)
  65. return
  66. }
  67. c.SetData(resp).Json()
  68. }