mng_user.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. // user get user by sysid.
  8. func user(c *bm.Context) {
  9. var (
  10. params = c.Request.Form
  11. system string
  12. )
  13. if system = params.Get("system"); system == "" {
  14. c.JSON(nil, ecode.RequestErr)
  15. return
  16. }
  17. c.JSON(svr.User(c, system), nil)
  18. }
  19. // saveUser save user.
  20. func saveUser(c *bm.Context) {
  21. var (
  22. params = c.Request.Form
  23. roleID, userID int64
  24. name string
  25. err error
  26. )
  27. if name = params.Get("user_name"); name == "" {
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. roleIDStr := params.Get("role_id")
  32. if roleID, err = strconv.ParseInt(roleIDStr, 10, 64); err != nil {
  33. c.JSON(nil, ecode.RequestErr)
  34. return
  35. }
  36. userIDStr := params.Get("user_id")
  37. userID, _ = strconv.ParseInt(userIDStr, 10, 64)
  38. system := params.Get("system")
  39. if userID == 0 && system == "" {
  40. c.JSON(nil, ecode.RequestErr)
  41. return
  42. }
  43. c.JSON(nil, svr.SaveUser(c, roleID, userID, system, name))
  44. }
  45. // delUser del user.
  46. func delUser(c *bm.Context) {
  47. var (
  48. params = c.Request.Form
  49. userID int64
  50. err error
  51. )
  52. userIDStr := params.Get("user_id")
  53. if userID, err = strconv.ParseInt(userIDStr, 10, 64); err != nil {
  54. c.JSON(nil, ecode.RequestErr)
  55. return
  56. }
  57. c.JSON(nil, svr.DelUser(c, userID))
  58. }