base_not_auth.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package controllers
  2. import (
  3. "fmt"
  4. "hongze/hongze_mobile_admin/utils"
  5. "net/url"
  6. "strings"
  7. )
  8. //不需要授权的基类
  9. type BaseNotAuth struct {
  10. BaseCommon
  11. }
  12. func (this *BaseNotAuth) Prepare() {
  13. var requestBody string
  14. method := this.Ctx.Input.Method()
  15. if method == "GET" {
  16. requestBody = this.Ctx.Request.RequestURI
  17. } else {
  18. requestBody, _ = url.QueryUnescape(string(this.Ctx.Input.RequestBody))
  19. }
  20. fmt.Println("requestBody:", requestBody)
  21. ip := this.Ctx.Input.IP()
  22. fmt.Println("ip:", ip)
  23. apiLog.Println("请求地址:", this.Ctx.Input.URI(), "RequestBody:", requestBody, "IP:", ip)
  24. authorization := this.Ctx.Input.Header("Authorization")
  25. if authorization == "" {
  26. cookie := this.Ctx.GetCookie("rddp_access_token")
  27. utils.FileLog.Info("authorization:%s,cookie:%s", authorization, cookie)
  28. authorization = cookie
  29. }
  30. uri := this.Ctx.Input.URI()
  31. utils.FileLog.Info("URI:%s", uri)
  32. if strings.Contains(uri, "/api/wechat/login") {
  33. authorization = ""
  34. }
  35. //if authorization != "" {
  36. // session, err := models.GetSessionByToken(authorization)
  37. // if err != nil {
  38. // if err.Error() == utils.ErrNoRow() {
  39. // this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "Token 信息已变更:Token: " + authorization}, false, false)
  40. // this.StopRun()
  41. // return
  42. // }
  43. // this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取用户信息异常,Eerr:" + err.Error()}, false, false)
  44. // this.StopRun()
  45. // return
  46. // }
  47. // if session == nil {
  48. // this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "sesson is empty "}, false, false)
  49. // this.StopRun()
  50. // return
  51. // }
  52. //
  53. // var wxUser *models.WxUserItem
  54. // if session.UserId > 0 {
  55. // tmpWxUser, tmpErr := services.GetWxUserItemByUserId(session.UserId, utils.WxPcPlatform)
  56. // wxUser = tmpWxUser
  57. // err = tmpErr
  58. // } else if session.OpenId != "" {
  59. // tmpWxUser, tmpErr := services.GetWxUserItemByOpenId(session.OpenId)
  60. // wxUser = tmpWxUser
  61. // err = tmpErr
  62. // } else {
  63. // this.JSON(models.BaseResponse{Ret: 408, Msg: "数据异常!", ErrMsg: "sesson is empty "}, false, false)
  64. // this.StopRun()
  65. // return
  66. // }
  67. // //wxUser, err := models.GetWxUserItemByUserId(session.UserId)
  68. // //wxUser, err := services.GetWxUserItemByOpenId(session.OpenId)
  69. // if err != nil {
  70. // //没有找到记录
  71. // if err.Error() == utils.ErrNoRow() {
  72. // this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "获取admin 信息失败 " + strconv.Itoa(session.UserId)}, false, false)
  73. // this.StopRun()
  74. // return
  75. // }
  76. // this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取wx_user信息异常,Eerr:" + err.Error()}, false, false)
  77. // this.StopRun()
  78. // return
  79. // }
  80. // if wxUser == nil {
  81. // this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "admin is empty "}, false, false)
  82. // this.StopRun()
  83. // return
  84. // }
  85. // this.User = wxUser
  86. //}
  87. //this.Token = authorization
  88. }