mng_auth.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. // auth get auth by sysid.
  8. func auth(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.Auth(c, system), nil)
  18. }
  19. // saveAuth save auth.
  20. func saveAuth(c *bm.Context) {
  21. var (
  22. params = c.Request.Form
  23. authID int64
  24. authName, authFlag string
  25. )
  26. if authName = params.Get("auth_name"); authName == "" {
  27. c.JSON(nil, ecode.RequestErr)
  28. return
  29. }
  30. authIDStr := params.Get("auth_id")
  31. authID, _ = strconv.ParseInt(authIDStr, 10, 64)
  32. system := params.Get("system")
  33. if authID == 0 && system == "" {
  34. c.JSON(nil, ecode.RequestErr)
  35. return
  36. }
  37. authFlag = params.Get("auth_flag")
  38. if authID == 0 && system != "" && authFlag == "" {
  39. c.JSON(nil, ecode.RequestErr)
  40. return
  41. }
  42. c.JSON(nil, svr.SaveAuth(c, authID, system, authName, authFlag))
  43. }
  44. // delAuth del auth.
  45. func delAuth(c *bm.Context) {
  46. var (
  47. params = c.Request.Form
  48. authID int64
  49. err error
  50. )
  51. authIDStr := params.Get("auth_id")
  52. if authID, err = strconv.ParseInt(authIDStr, 10, 64); err != nil {
  53. c.JSON(nil, ecode.RequestErr)
  54. return
  55. }
  56. c.JSON(nil, svr.DelAuth(c, authID))
  57. }
  58. // authRelation update authRelation.
  59. func authRelation(c *bm.Context) {
  60. var (
  61. params = c.Request.Form
  62. roleID, authID int64
  63. state int
  64. err error
  65. )
  66. roleIDStr := params.Get("role_id")
  67. if roleID, err = strconv.ParseInt(roleIDStr, 10, 64); err != nil {
  68. c.JSON(nil, ecode.RequestErr)
  69. return
  70. }
  71. authIDStr := params.Get("auth_id")
  72. if authID, err = strconv.ParseInt(authIDStr, 10, 64); err != nil {
  73. c.JSON(nil, ecode.RequestErr)
  74. return
  75. }
  76. stateStr := params.Get("state")
  77. if state, err = strconv.Atoi(stateStr); err != nil {
  78. c.JSON(nil, ecode.RequestErr)
  79. return
  80. }
  81. c.JSON(nil, svr.AuthRelation(c, roleID, authID, state))
  82. }