- 绑定认证方式前,先删除可能的相同的认证方式

This commit is contained in:
gazebo
2019-09-02 14:53:18 +08:00
parent c0c79c368d
commit e4f1812337

View File

@@ -240,7 +240,6 @@ 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{
@@ -261,21 +260,12 @@ 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 authers[authInfo.AuthBindInfo.Type].UnbindAuth(user.GetID(), authInfo.GetAuthType(), user.GetName()) == nil {
if authers[authInfo.AuthBindInfo.Type].AddAuthBind(authInfo.AuthBindInfo, user.GetName()) == nil {
// todo用户类型应该要与RegisterUser一起统一处理
userProvider.UpdateUserType(user.GetID(), handler.GetUserType(), UpdateUserTypeAdd)
}
}
}
}
} else {
err = ErrIllegalAuthType
@@ -318,6 +308,7 @@ func AddAuthBind(user IUser, newAuthInfo *AuthInfo) (err error) {
err = userProvider.UpdateUserEmail(user.GetID(), newAuthInfo.AuthBindInfo.AuthID)
} else {
newAuthInfo.AuthBindInfo.UserID = user.GetID()
authers[newAuthInfo.AuthBindInfo.Type].UnbindAuth(user.GetID(), newAuthInfo.GetAuthType(), user.GetName())
err = authers[newAuthInfo.AuthBindInfo.Type].AddAuthBind(newAuthInfo.AuthBindInfo, user.GetName())
}
return err