check_cygx_auth.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package middleware
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/models/tables/wx_user"
  6. "hongze/hongze_yb/services/company"
  7. "hongze/hongze_yb/services/user"
  8. "hongze/hongze_yb/utils"
  9. "strconv"
  10. )
  11. // CheckCygxAuth 如果带thirdCode就可以看,如果有权限也给其他权限
  12. func CheckCygxAuth() gin.HandlerFunc {
  13. return func(c *gin.Context) {
  14. userInfo := user.GetInfoByClaims(c)
  15. thirdCodeEncrypt := c.Request.Header.Get("thirdCode")
  16. if thirdCodeEncrypt != "" {
  17. thirdCode := utils.DesBase64Decrypt([]byte(thirdCodeEncrypt))
  18. userId, err := strconv.Atoi(string(thirdCode))
  19. if err != nil {
  20. response.FailMsg("参数错误", "参数错误", c)
  21. c.Abort()
  22. return
  23. }
  24. _, err = wx_user.GetByUserId(userId)
  25. if err != nil {
  26. response.FailMsg("获取用户信息失败", "获取用户信息失败", c)
  27. c.Abort()
  28. return
  29. }
  30. } else {
  31. ok, checkInfo, _, err := company.CheckBaseFiccPermission(userInfo.CompanyID, int(userInfo.UserID))
  32. if err != nil {
  33. response.FailMsg("用户权限验证失败", "CheckBaseAuth-用户权限验证失败"+err.Error(), c)
  34. c.Abort()
  35. return
  36. }
  37. if !ok {
  38. response.AuthError(checkInfo, "暂无权限", c)
  39. c.Abort()
  40. return
  41. }
  42. }
  43. c.Next()
  44. }
  45. }