- first edition of auth2
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package jxcontext
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
@@ -12,11 +14,16 @@ import (
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type IAuther interface {
|
||||
GetAuthID() string
|
||||
GetAuthType() string
|
||||
}
|
||||
|
||||
type Context struct {
|
||||
rootTask tasksch.ITask
|
||||
token string
|
||||
accessUUID string
|
||||
userInfo *auth.LoginInfo
|
||||
userInfo IAuther //*auth.LoginInfo
|
||||
w http.ResponseWriter
|
||||
r *http.Request
|
||||
mapData map[interface{}]interface{}
|
||||
@@ -56,7 +63,17 @@ func New(rootTask tasksch.ITask, token string, w http.ResponseWriter, r *http.Re
|
||||
mapData: make(map[interface{}]interface{}),
|
||||
accessUUID: utils.GetUUID(),
|
||||
}
|
||||
ctx.userInfo, err = auth.GetUserInfo(token)
|
||||
if auth2.IsV2Token(token) {
|
||||
authInfo, err2 := auth2.GetUserInfo(token)
|
||||
if err = err2; err == nil {
|
||||
ctx.userInfo = authInfo
|
||||
if authInfo.TokenType != auth2.TokenTypeNormal {
|
||||
err = errors.New("需要正式TOKEN")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx.userInfo, err = auth.GetUserInfo(token)
|
||||
}
|
||||
if err != nil && beego.BConfig.RunMode == "prod" {
|
||||
globals.SugarLogger.Debugf("token is invalid, token:%s", token)
|
||||
return nil, model.ErrCodeTokenIsInvalid, err
|
||||
@@ -67,7 +84,7 @@ func New(rootTask tasksch.ITask, token string, w http.ResponseWriter, r *http.Re
|
||||
func (ctx *Context) GetUserName() string {
|
||||
userName := ctx.token
|
||||
if ctx.userInfo != nil {
|
||||
userName = ctx.userInfo.ID
|
||||
userName = ctx.userInfo.GetAuthID()
|
||||
}
|
||||
if len(userName) > MaxUserNameLen {
|
||||
userName = userName[:MaxUserNameLen]
|
||||
@@ -77,7 +94,7 @@ func (ctx *Context) GetUserName() string {
|
||||
|
||||
func (ctx *Context) GetLoginID() string {
|
||||
if ctx.userInfo != nil {
|
||||
return ctx.userInfo.ID
|
||||
return ctx.userInfo.GetAuthID()
|
||||
}
|
||||
return ""
|
||||
|
||||
@@ -85,7 +102,7 @@ func (ctx *Context) GetLoginID() string {
|
||||
|
||||
func (ctx *Context) GetLoginType() string {
|
||||
if ctx.userInfo != nil {
|
||||
return ctx.userInfo.LoginType
|
||||
return ctx.userInfo.GetAuthType()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -98,7 +115,7 @@ func (ctx *Context) GetAccessUUID() string {
|
||||
return ctx.accessUUID
|
||||
}
|
||||
|
||||
func (ctx *Context) GetLoginInfo() *auth.LoginInfo {
|
||||
func (ctx *Context) GetLoginInfo() IAuther {
|
||||
return ctx.userInfo
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user