互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package controllers
  2. import (
  3. "hudongzhuanjia/libs/jwt"
  4. "hudongzhuanjia/utils/code"
  5. "hudongzhuanjia/utils/define"
  6. )
  7. //执行路由方法前校验登陆态,并且解析page、pageSize
  8. type AuthorCtl struct {
  9. BaseCtl
  10. claims *jwt.Claims
  11. }
  12. func (t *AuthorCtl) Prepare() {
  13. t.BaseCtl.Prepare()
  14. token := ""
  15. if tokenStr, ok := t.Request.SESSION[define.TOKEN]; ok {
  16. token = tokenStr
  17. } else if tokenStr, ok = t.Request.REQUEST[define.TOKEN]; ok {
  18. token = tokenStr
  19. } else if tokenStr, ok = t.Request.HEADER[define.TOKEN]; ok {
  20. token = tokenStr
  21. } else {
  22. var param = make(map[string]interface{}, 0)
  23. err := t.RequestToStruct(&param)
  24. t.CheckErr(err)
  25. if tokenStr, ok := param[define.TOKEN]; ok {
  26. token = tokenStr.(string)
  27. }
  28. }
  29. claims, err := jwt.ParseAccessToken(token)
  30. if err != nil {
  31. t.ERROR("token 失效", code.MSG_ERR_Authority)
  32. }
  33. t.claims = claims
  34. // 最后多地区:子账号的area_id = area_id, 但是主账号的area_id 需要通过activity_id 进行获取
  35. }
  36. func (t *AuthorCtl) MustGetUID() int64 {
  37. return t.claims.AccountId
  38. }
  39. // token 应该携带某个主活动i
  40. func (t *AuthorCtl) MustGetActivityId() int64 {
  41. return t.MustGetInt64("activity_id")
  42. }
  43. func (t *AuthorCtl) MustGetCustomerId() int64 {
  44. return t.claims.CustomerId
  45. }
  46. func (t *AuthorCtl) MustGetCustomerPid() int64 {
  47. return t.claims.CustomerPid
  48. }
  49. func (t *AuthorCtl) MustGetAreaId() int64 {
  50. return t.claims.AreaId
  51. }
  52. // 对各种角色进行不同的接口权限限定
  53. // role: main sub entry user : 主账号 子账号 录入人员 用户