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

package controllers
import (
"hudongzhuanjia/libs/jwt"
"hudongzhuanjia/models"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
)
//执行路由方法前校验登陆态,并且解析page、pageSize
type AuthorCtl struct {
BaseCtl
AccountId int
AccountType string
claims *jwt.Claims
}
func (t *AuthorCtl) Prepare() {
t.BaseCtl.Prepare()
//skip, _ := t.GetInt("skip")
//if skip != 0 {
//t.AccountId
//t.claims = &jwt.Claims{
// AccountType: "customer",
// AccountId: skip,
// CustomerId: 1,
// CustomerPid: 0,
// ActivityId: 1,
// AreaId: 1,
// StandardClaims: jwt2.StandardClaims{},
//}
//return
//} else {
token := ""
if t.Request.SESSION[define.TOKEN] != "" {
token = t.Request.SESSION[define.TOKEN]
} else if t.Request.REQUEST[define.TOKEN] != "" {
token = t.Request.REQUEST[define.TOKEN]
} else if t.Request.HEADER[define.TOKEN] != "" {
token = t.Request.HEADER[define.TOKEN]
} else {
var param = make(map[string]interface{}, 0)
err := t.RequestToStruct(&param)
t.CheckErr(err)
if param[define.TOKEN] != nil {
token = param[define.TOKEN].(string)
}
}
if token == "" {
t.ERROR("token失效", code.MSG_ERR_Authority)
}
_type, id, err := models.ParseToken(token)
if err != nil {
t.ERROR("token失效", code.MSG_ERR_Authority)
return
}
t.AccountType = _type
t.AccountId = id
//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) GetAccountId() int {
return t.AccountId
}
func (t *AuthorCtl) GetAccountType() string {
return t.AccountType
}