作者 yangfu

解析token

... ... @@ -13,8 +13,8 @@ type ResetPhoneCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 短信验证码
SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"`
OldPhone string `cname:"" json:"oldPhone" valid:"Required"`
SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"`
//OldPhone string `cname:"" json:"oldPhone" valid:"Required"`
NewPhone string `cname:"" json:"newPhone" valid:"Required"`
}
... ...
... ... @@ -76,7 +76,7 @@ func (srv UserService) ChangePhone(resetPhoneCommand *command.ResetPhoneCommand)
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
_, err = creationUserGateway.AuthResetPhone(allied_creation_user.ReqAuthResetPhone{
UserId: resetPhoneCommand.Operator.UserId,
OldPhone: resetPhoneCommand.OldPhone,
OldPhone: resetPhoneCommand.Operator.Phone,
NewPhone: resetPhoneCommand.NewPhone,
})
if err != nil {
... ...
... ... @@ -2,8 +2,9 @@ package domain
// 登录系统的操作人员 可以从toke中获取数据
type Operator struct {
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
UserBaseId int64 `json:"userBaseId"`
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
UserBaseId int64 `json:"userBaseId"`
Phone string `json:"phone"`
}
... ...
package beego
import (
"encoding/json"
"github.com/beego/beego/v2/server/web/context"
"os"
"strconv"
... ... @@ -30,4 +32,11 @@ func init() {
web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors())
web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(log.Logger))
web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(log.Logger), web.WithReturnOnOutput(false))
web.InsertFilter("/v1/app1/*", web.BeforeExec, filters.SecureHandler(
filters.WithEnableCheckTimestamp(false),
filters.WithOnInvalidRequest(func(ctx *context.Context) {
headerData, _ := json.Marshal(ctx.Input.Context.Request.Header)
log.Logger.Info("签名验证失败:" + string(headerData))
}),
))
}
... ...
... ... @@ -37,10 +37,14 @@ func (controller *baseController) GetOrgId() int64 {
}
func (controller *baseController) GetOperator() domain.Operator {
token := controller.Ctx.Input.Header("X-Mmm-Accesstoken")
loginToken := &domain.LoginToken{}
loginToken.ParseToken(token)
return domain.Operator{
UserId: 9,
CompanyId: 23,
OrgId: 45,
UserBaseId: 5,
UserId: loginToken.UserId,
CompanyId: loginToken.CompanyId,
OrgId: loginToken.OrgId,
UserBaseId: loginToken.UserBaseId,
Phone: loginToken.Account,
}
}
... ...