From 4b362baea97f7fe18724d2ca3876eb33e9ef0942 Mon Sep 17 00:00:00 2001 From: gazebo Date: Sat, 9 Mar 2019 14:20:21 +0800 Subject: [PATCH] - fix bug in UnionFindAuthBind --- business/auth2/auth2.go | 1 + business/auth2/authprovider/defauther.go | 9 ++++++++- business/model/dao/dao_user2.go | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index b2023d43c..6bdd666cd 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -190,6 +190,7 @@ func Login(authType, authID, authIDType, authSecret string) (authInfo *AuthInfo, realAuthID = user.GetID() } if authBindEx, err = handler.VerifySecret(realAuthID, authSecret); err == nil { + globals.SugarLogger.Debugf("auth2 Login authBindEx:%s", utils.Format4Output(authBindEx, false)) if authBindEx == nil { // mobile, email会返回nil(表示不会新建AuthBind实体) user = userProvider.GetUser(authID, authIDType) authBindEx = &AuthBindEx{ diff --git a/business/auth2/authprovider/defauther.go b/business/auth2/authprovider/defauther.go index 593728c93..5cf9cade1 100644 --- a/business/auth2/authprovider/defauther.go +++ b/business/auth2/authprovider/defauther.go @@ -43,7 +43,14 @@ func (a *DefAuther) Logout(authInfo *auth2.AuthInfo) error { func (a *DefAuther) UnionFindAuthBind(curAuthType string, unionAuthTypeList []string, openID, unionID string, authDetail interface{}) (authBindEx *auth2.AuthBindEx, err error) { db := dao.GetDB() var authBind *model.AuthBind - if authBind, err = dao.GetAuthBind(db, "", curAuthType, openID); dao.IsNoRowsError(err) { // 直接找不到 + if authBind, err = dao.GetAuthBind(db, "", curAuthType, openID); err == nil { // 直接找到了 + authBindEx = &auth2.AuthBindEx{ + AuthBind: *authBind, + } + if authDetail != nil { + authBindEx.DetailData = string(utils.MustMarshal(authDetail)) + } + } else if dao.IsNoRowsError(err) { // 直接找不到,尝试unionID if unionID != "" { // 且有unionID var authBindList []*model.AuthBind if authBindList, err = dao.GetAuthBindsByAuthID2(db, unionID, unionAuthTypeList); err == nil && len(authBindList) > 0 { // 通过unionID找到至少一个认证方式 diff --git a/business/model/dao/dao_user2.go b/business/model/dao/dao_user2.go index 7d6846c6a..eeb1380a1 100644 --- a/business/model/dao/dao_user2.go +++ b/business/model/dao/dao_user2.go @@ -18,7 +18,7 @@ func GetUserByID(db *DaoDB, fieldName, fieldValue string) (user *model.User, err utils.DefaultTimeValue, fieldValue, } - globals.SugarLogger.Debugf("GetUserByID sql:%s, sqlParams:%s", sql, utils.Format4Output(sql, false)) + globals.SugarLogger.Debugf("GetUserByID sql:%s, sqlParams:%s", sql, utils.Format4Output(sqlParams, false)) err = GetRow(db, &user, sql, sqlParams...) return user, err }