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.
|
|
package controllers
import ( jwt2 "github.com/dgrijalva/jwt-go" "hudongzhuanjia/libs/jwt" "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" )
//执行路由方法前校验登陆态,并且解析page、pageSize
type AuthorCtl struct { BaseCtl claims *jwt.Claims }
func (t *AuthorCtl) Prepare() { t.BaseCtl.Prepare() skip, _ := t.GetInt64("skip") if skip != 0 { t.claims = &jwt.Claims{ AccountType: "customer", AccountId: skip, CustomerId: 1, CustomerPid: 0, ActivityId: 1, AreaId: 1, StandardClaims: jwt2.StandardClaims{}, } return } else { token := "" if tokenStr, ok := t.Request.SESSION[define.TOKEN]; ok { token = tokenStr } else if tokenStr, ok = t.Request.REQUEST[define.TOKEN]; ok { token = tokenStr } else if tokenStr, ok = t.Request.HEADER[define.TOKEN]; ok { token = tokenStr } else { var param = make(map[string]interface{}, 0) err := t.RequestToStruct(¶m) t.CheckErr(err) if tokenStr, ok := param[define.TOKEN]; ok { token = tokenStr.(string) } } claims, err := jwt.ParseAccessToken(token) if err != nil { t.ERROR("token 失效", code.MSG_ERR_Authority) } t.claims = claims // 最后多地区:子账号的area_id = area_id, 但是主账号的area_id 需要通过activity_id 进行获取
} }
func (t *AuthorCtl) MustGetUID() int64 { return t.claims.AccountId }
func (t *AuthorCtl) MustGetCustomerId() int64 { if t.claims.CustomerId == 0 { return t.MustGetInt64("customer_id") } return t.claims.CustomerId }
func (t *AuthorCtl) MustGetAreaId() int64 { areaId, exist := t.GetInt64("area_id") if !exist { areaId = t.claims.AreaId } if areaId == 0 { t.ERROR("area_id 不能为空", code.MSG_ERR_Param) } return areaId }
// 对各种角色进行不同的接口权限限定
// role: main sub entry user : 主账号 子账号 录入人员 用户
|