prehandler.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package http
  2. import (
  3. "net/http"
  4. "strconv"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/render"
  8. )
  9. func checkgroup() bm.HandlerFunc {
  10. return func(ctx *bm.Context) {
  11. uid, _ := getUIDName(ctx)
  12. role, err := srv.CheckGroup(ctx, uid)
  13. if err != nil || role == 0 {
  14. data := map[string]interface{}{
  15. "code": ecode.RequestErr,
  16. "message": "权限错误",
  17. }
  18. ctx.Render(http.StatusOK, render.MapJSON(data))
  19. ctx.Abort()
  20. return
  21. }
  22. }
  23. }
  24. // 校验任务操作权限
  25. func checkowner() bm.HandlerFunc {
  26. return func(ctx *bm.Context) {
  27. tidS := ctx.Request.Form.Get("task_id")
  28. tid, err := strconv.Atoi(tidS)
  29. if err != nil {
  30. ctx.JSON(nil, ecode.RequestErr)
  31. ctx.Abort()
  32. return
  33. }
  34. uid, _ := getUIDName(ctx)
  35. if err := srv.CheckOwner(ctx, int64(tid), uid); err != nil {
  36. data := map[string]interface{}{
  37. "code": ecode.RequestErr,
  38. "message": err.Error(),
  39. }
  40. ctx.Render(http.StatusOK, render.MapJSON(data))
  41. ctx.Abort()
  42. return
  43. }
  44. }
  45. }