- user GetUserTag in jxcontext.Context.GetUserName

This commit is contained in:
gazebo
2019-03-12 17:08:41 +08:00
parent 6693bd4bf5
commit 8ce4ee0be9
3 changed files with 19 additions and 1 deletions

View File

@@ -76,3 +76,16 @@ func (a *AuthInfo) GetAuthID() string {
func (a *AuthInfo) GetAuthType() string { func (a *AuthInfo) GetAuthType() string {
return a.AuthBindInfo.Type return a.AuthBindInfo.Type
} }
func (a *AuthInfo) GetUserTag() string {
userTag := a.UserID2
if userTag == "" {
if a.AuthBindInfo.UserHint != nil {
userTag = a.AuthBindInfo.UserHint.Mobile
}
if userTag == "" {
userTag = a.AuthBindInfo.AuthID
}
}
return userTag
}

View File

@@ -115,3 +115,7 @@ func (a *LoginInfo) GetAuthID() string {
func (a *LoginInfo) GetAuthType() string { func (a *LoginInfo) GetAuthType() string {
return a.LoginType return a.LoginType
} }
func (a *LoginInfo) GetUserTag() string {
return a.ID
}

View File

@@ -17,6 +17,7 @@ import (
type IAuther interface { type IAuther interface {
GetAuthID() string GetAuthID() string
GetAuthType() string GetAuthType() string
GetUserTag() string
} }
type Context struct { type Context struct {
@@ -96,7 +97,7 @@ func New(rootTask tasksch.ITask, token string, w http.ResponseWriter, r *http.Re
func (ctx *Context) GetUserName() string { func (ctx *Context) GetUserName() string {
userName := ctx.token userName := ctx.token
if ctx.userInfo != nil { if ctx.userInfo != nil {
userName = ctx.userInfo.GetAuthID() userName = ctx.userInfo.GetUserTag()
} }
if len(userName) > MaxUserNameLen { if len(userName) > MaxUserNameLen {
userName = userName[:MaxUserNameLen] userName = userName[:MaxUserNameLen]