互动
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.

76 lines
1.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 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/models"
  5. "hudongzhuanjia/utils/code"
  6. "hudongzhuanjia/utils/define"
  7. )
  8. //执行路由方法前校验登陆态,并且解析page、pageSize
  9. type AuthorCtl struct {
  10. BaseCtl
  11. AccountId int
  12. AccountType string
  13. claims *jwt.Claims
  14. }
  15. func (t *AuthorCtl) Prepare() {
  16. t.BaseCtl.Prepare()
  17. //skip, _ := t.GetInt("skip")
  18. //if skip != 0 {
  19. //t.AccountId
  20. //t.claims = &jwt.Claims{
  21. // AccountType: "customer",
  22. // AccountId: skip,
  23. // CustomerId: 1,
  24. // CustomerPid: 0,
  25. // ActivityId: 1,
  26. // AreaId: 1,
  27. // StandardClaims: jwt2.StandardClaims{},
  28. //}
  29. //return
  30. //} else {
  31. token := ""
  32. if t.Request.SESSION[define.TOKEN] != "" {
  33. token = t.Request.SESSION[define.TOKEN]
  34. } else if t.Request.REQUEST[define.TOKEN] != "" {
  35. token = t.Request.REQUEST[define.TOKEN]
  36. } else if t.Request.HEADER[define.TOKEN] != "" {
  37. token = t.Request.HEADER[define.TOKEN]
  38. } else {
  39. var param = make(map[string]interface{}, 0)
  40. err := t.RequestToStruct(&param)
  41. t.CheckErr(err)
  42. if param[define.TOKEN] != nil {
  43. token = param[define.TOKEN].(string)
  44. }
  45. }
  46. if token == "" {
  47. t.ERROR("token失效", code.MSG_ERR_Authority)
  48. }
  49. _type, id, err := models.ParseToken(token)
  50. if err != nil {
  51. t.ERROR("token失效", code.MSG_ERR_Authority)
  52. return
  53. }
  54. t.AccountType = _type
  55. t.AccountId = id
  56. //claims, err := jwt.ParseAccessToken(token)
  57. //if err != nil {
  58. // t.ERROR("token 失效", code.MSG_ERR_Authority)
  59. //}
  60. //t.claims = claims
  61. // 最后多地区:子账号的area_id = area_id, 但是主账号的area_id 需要通过activity_id 进行获取
  62. //}
  63. }
  64. func (t *AuthorCtl) GetAccountId() int {
  65. return t.AccountId
  66. }
  67. func (t *AuthorCtl) GetAccountType() string {
  68. return t.AccountType
  69. }