- auth2添加固定TOKEN
This commit is contained in:
@@ -88,6 +88,20 @@ var (
|
||||
AuthTypeEmail: regexp.MustCompile(`^[A-Za-z0-9_\-\.]+\@[A-Za-z0-9_\-]+(\.[A-Za-z]+){1,5}$`),
|
||||
AuthTypeMobile: regexp.MustCompile(`^1[345789]\d{9}$`),
|
||||
}
|
||||
|
||||
// 永久全局的TOKEN,内部使用
|
||||
fixedTokenMap = map[string]*AuthInfo{
|
||||
"85e60d6a-f1f8-4837-9c7d-d7072b0ba1c6": &AuthInfo{
|
||||
UserBasic: UserBasic{
|
||||
UserID2: "shifengfix",
|
||||
Mobile: "18048531223",
|
||||
Name: "石峰固定",
|
||||
},
|
||||
AuthBindInfo: &AuthBindEx{},
|
||||
LoginTime: utils.ZeroTimeValue,
|
||||
ExpiresAt: 0,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -106,6 +120,16 @@ var (
|
||||
|
||||
func init() {
|
||||
authers = make(map[string]IAuther)
|
||||
|
||||
InitFixedToken()
|
||||
}
|
||||
|
||||
func InitFixedToken() {
|
||||
for k, v := range fixedTokenMap {
|
||||
v.UserID = k
|
||||
v.Token = k
|
||||
v.TokenType = TokenTypeNormal
|
||||
}
|
||||
}
|
||||
|
||||
func Init(userProvider2 IUserProvider) {
|
||||
@@ -116,6 +140,10 @@ func RegisterAuther(authType string, handler IAuther) {
|
||||
authers[authType] = handler
|
||||
}
|
||||
|
||||
func getFixedTokenName(token string) *AuthInfo {
|
||||
return fixedTokenMap[token]
|
||||
}
|
||||
|
||||
func createAuthInfo(user IUser, authBindInfo *AuthBindEx) (authInfo *AuthInfo) {
|
||||
token, tokenType := createToken(user)
|
||||
expireDuration := DefTokenDuration
|
||||
@@ -303,6 +331,9 @@ func RemoveUserInfo(token string) {
|
||||
}
|
||||
|
||||
func GetTokenInfo(token string) (authInfo *AuthInfo, err error) {
|
||||
if authInfo = getFixedTokenName(token); authInfo != nil {
|
||||
return authInfo, nil
|
||||
}
|
||||
if err = api.Cacher.GetAs(token, &authInfo); err == nil {
|
||||
return authInfo, nil
|
||||
}
|
||||
@@ -348,6 +379,9 @@ func createToken(user IUser) (token string, tokenType int) {
|
||||
}
|
||||
|
||||
func GetTokenType(token string) (tokenType int) {
|
||||
if getFixedTokenName(token) != nil {
|
||||
return TokenTypeNormal
|
||||
}
|
||||
tokenType = TokenTypeNone
|
||||
if token != "" {
|
||||
tokenPartList := strings.Split(token, TokenTypeSep)
|
||||
@@ -361,6 +395,9 @@ func GetTokenType(token string) (tokenType int) {
|
||||
}
|
||||
|
||||
func IsV2Token(token string) bool {
|
||||
if getFixedTokenName(token) != nil {
|
||||
return true
|
||||
}
|
||||
tokenPartList := strings.Split(token, TokenTypeSep)
|
||||
return len(tokenPartList) > 1 && tokenPartList[1] == TokenVer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user