- 认证通过且通过手机(或邮箱)能找到用户,在没有相应认证方式的情况下,自动绑定此认证方式
This commit is contained in:
@@ -54,10 +54,17 @@ type IUser interface {
|
||||
GetName() string
|
||||
}
|
||||
|
||||
const (
|
||||
UpdateUserTypeAdd = 1
|
||||
UpdateUserTypeDelete = 2
|
||||
UpdateUserTypeUpdate = 3
|
||||
)
|
||||
|
||||
type IUserProvider interface {
|
||||
GetUser(authID, authIDType string) (user IUser)
|
||||
UpdateUserMobile(userID string, mobile string) (err error)
|
||||
UpdateUserEmail(userID string, email string) (err error)
|
||||
UpdateUserType(userID string, userTypeMask int8, updateType int) (err error)
|
||||
// CreateUser(userID2, mobile, email, name string) (user IUser, err error)
|
||||
}
|
||||
|
||||
@@ -73,6 +80,7 @@ type IAuther interface {
|
||||
AddAuthBind(authBindEx *AuthBindEx, userName string) (err error)
|
||||
UnbindAuth(userID, authType, userName string) (err error)
|
||||
Logout(authInfo *AuthInfo) (err error)
|
||||
GetUserType() (userType int8)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -232,6 +240,7 @@ func Login(authType, authID, authIDType, authSecret string) (authInfo *AuthInfo,
|
||||
}
|
||||
if authBindEx, err = handler.VerifySecret(realAuthID, authSecret); err == nil {
|
||||
// globals.SugarLogger.Debugf("auth2 Login authBindEx:%s", utils.Format4Output(authBindEx, false))
|
||||
needAutoAddAuthBind := false
|
||||
if authBindEx == nil { // mobile, email会返回nil(表示不会新建AuthBind实体)
|
||||
user = userProvider.GetUser(authID, authIDType)
|
||||
authBindEx = &AuthBindEx{
|
||||
@@ -252,12 +261,19 @@ func Login(authType, authID, authIDType, authSecret string) (authInfo *AuthInfo,
|
||||
}
|
||||
if user != nil {
|
||||
authBindEx.UserID = user.GetID()
|
||||
needAutoAddAuthBind = true
|
||||
}
|
||||
} else if authBindEx.UserID != "" {
|
||||
user = userProvider.GetUser(authBindEx.UserID, UserIDID)
|
||||
}
|
||||
}
|
||||
authInfo = createAuthInfo(user, authBindEx)
|
||||
if needAutoAddAuthBind {
|
||||
if AddAuthBind(user, authInfo) == nil {
|
||||
// todo,用户类型应该要与RegisterUser一起统一处理
|
||||
userProvider.UpdateUserType(user.GetID(), handler.GetUserType(), UpdateUserTypeAdd)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = ErrIllegalAuthType
|
||||
|
||||
Reference in New Issue
Block a user