Files
jx-callback/business/auth2/auth_info.go

103 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package auth2
import (
"time"
"git.rosy.net.cn/jx-callback/business/model"
)
const (
TokenTypeNone = 0
TokenTypeNormal = 1
TokenTypeOnlyAuth = 2
)
type UserBasic struct {
UserID string `json:"userID"`
UserID2 string `json:"userID2"`
Mobile string `json:"mobile"`
Email string `json:"email"`
Name string `json:"name"`
Avatar string `json:"avatar"`
}
func (u *UserBasic) GetID() string {
return u.UserID
}
func (u *UserBasic) GetID2() string {
return u.UserID2
}
func (u *UserBasic) GetMobile() string {
return u.Mobile
}
func (u *UserBasic) GetEmail() string {
return u.Email
}
func (u *UserBasic) GetName() string {
return u.Name
}
func (u *UserBasic) GetAvatar() string {
return u.Avatar
}
func (u *UserBasic) UpdateByIUser(user IUser) {
if user != nil {
u.UserID = user.GetID()
u.UserID2 = user.GetID2()
u.Mobile = user.GetMobile()
u.Email = user.GetEmail()
u.Name = user.GetName()
u.Avatar = user.GetAvatar()
}
}
func (u *UserBasic) IsUserEmpty() bool {
return u.UserID == ""
}
type AuthBindEx struct {
model.AuthBind
UserData interface{} `json:"userData"` // 认证成功后得到的原始用户信息
UserHint *UserBasic `json:"userHint"` // 认证成功后得到的一些可能的基本用户信息主要有用信息是手机号email与用户名
}
type AuthInfo struct {
UserBasic // 登录成功后保存的用户信息
AuthBindInfo *AuthBindEx `json:"authBindInfo"`
LoginTime time.Time `json:"loginTime"`
ExpiresAt int64 `json:"expiresAt"`
Token string `json:"token"`
TokenType int `json:"tokenType"` // TOKEN类型
IsExistOpenID bool `json:"isExistOpenID"`
}
func (a *AuthInfo) GetAuthID() string {
return a.AuthBindInfo.AuthID
}
func (a *AuthInfo) GetAuthType() string {
return a.AuthBindInfo.Type
}
func (a *AuthInfo) GetAuthTypeID() string {
return a.AuthBindInfo.TypeID
}
func (a *AuthInfo) GetUserTag() string {
userTag := a.GetID2()
if userTag == "" {
if a.AuthBindInfo.UserHint != nil {
userTag = a.AuthBindInfo.UserHint.Mobile
}
if userTag == "" {
userTag = a.AuthBindInfo.AuthID
}
}
return userTag
}