|
|
@ -1,6 +1,7 @@ |
|
|
|
package controllers |
|
|
|
|
|
|
|
import ( |
|
|
|
jwt2 "github.com/dgrijalva/jwt-go" |
|
|
|
"hudongzhuanjia/libs/jwt" |
|
|
|
"hudongzhuanjia/utils/code" |
|
|
|
"hudongzhuanjia/utils/define" |
|
|
@ -14,27 +15,41 @@ type AuthorCtl struct { |
|
|
|
|
|
|
|
func (t *AuthorCtl) Prepare() { |
|
|
|
t.BaseCtl.Prepare() |
|
|
|
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 |
|
|
|
skip := t.MustGetInt("skip") |
|
|
|
if skip == 1 { |
|
|
|
t.claims = &jwt.Claims{ |
|
|
|
AccountType: "customer", |
|
|
|
AccountId: 16, |
|
|
|
CustomerId: 16, |
|
|
|
CustomerPid: 0, |
|
|
|
ActivityId: 101, |
|
|
|
AreaId: 101, |
|
|
|
StandardClaims: jwt2.StandardClaims{}, |
|
|
|
} |
|
|
|
return |
|
|
|
} 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) |
|
|
|
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 进行获取
|
|
|
|
} |
|
|
|
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 { |
|
|
|