认证支持同一类型多绑定
This commit is contained in:
@@ -31,7 +31,7 @@ func (a *Auther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx,
|
||||
if err == nil {
|
||||
userInfo, err2 := api.AliPayAPI.UserInfoShare(tokenInfo.AccessToken)
|
||||
if err = err2; err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthType, nil, userInfo.UserID, "", userInfo); err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthType, api.AliPayAPI.GetAppID(), nil, userInfo.UserID, "", userInfo); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
Name: userInfo.NickName,
|
||||
Avatar: userInfo.Avatar,
|
||||
|
||||
@@ -35,13 +35,17 @@ func (a *DefAuther) AddAuthBind(authBindEx *auth2.AuthBindEx, userName string) (
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *DefAuther) UnbindAuth(userID, authType, userName string) (err error) {
|
||||
globals.SugarLogger.Debugf("DefAuther.UnbindAuth userID:%s, authType:%s, userName:%s", userID, authType, userName)
|
||||
_, err = dao.DeleteEntityLogically(nil, &model.AuthBind{}, nil, userName, map[string]interface{}{
|
||||
func (a *DefAuther) UnbindAuth(userID, authType, authTypeID, userName string) (err error) {
|
||||
globals.SugarLogger.Debugf("DefAuther.UnbindAuth userID:%s, authType:%s, GetAuthTypeID:%s, userName:%s", userID, authType, authTypeID, userName)
|
||||
condition := map[string]interface{}{
|
||||
"UserID": userID,
|
||||
"Type": authType,
|
||||
model.FieldDeletedAt: utils.DefaultTimeValue,
|
||||
})
|
||||
}
|
||||
if authTypeID != "" {
|
||||
condition["TypeID"] = authTypeID
|
||||
}
|
||||
_, err = dao.DeleteEntityLogically(dao.GetDB(), &model.AuthBind{}, nil, userName, condition)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -59,9 +63,9 @@ func (a *DefAuther) GetUserType() (userType int8) {
|
||||
}
|
||||
|
||||
// 此函数用于联合(通过unionID)查找用户
|
||||
func (a *DefAuther) UnionFindAuthBind(curAuthType string, unionAuthTypeList []string, openID, unionID string, authDetail interface{}) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("UnionFindAuthBind curAuthType:%s, unionAuthTypeList:%v, openID:%s, unionID:%s, authDetail:%s",
|
||||
curAuthType, unionAuthTypeList, openID, unionID, utils.Format4Output(authDetail, true))
|
||||
func (a *DefAuther) UnionFindAuthBind(curAuthType, curAuthTypeID string, unionAuthTypeList []string, openID, unionID string, authDetail interface{}) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("UnionFindAuthBind curAuthType:%s, curAuthTypeID:%s, unionAuthTypeList:%v, openID:%s, unionID:%s, authDetail:%s",
|
||||
curAuthType, curAuthTypeID, unionAuthTypeList, openID, unionID, utils.Format4Output(authDetail, true))
|
||||
db := dao.GetDB()
|
||||
var authBind *model.AuthBind
|
||||
if authBind, err = dao.GetAuthBind(db, model.AuthBindTypeAuth, curAuthType, openID); err == nil { // 直接找到了
|
||||
@@ -77,6 +81,7 @@ func (a *DefAuther) UnionFindAuthBind(curAuthType string, unionAuthTypeList []st
|
||||
if authBindList, err = dao.GetUserBindAuthInfo(db, "", model.AuthBindTypeAuth, unionAuthTypeList, "", unionID); err == nil && len(authBindList) > 0 { // 通过unionID找到至少一个认证方式
|
||||
authBind = authBindList[0]
|
||||
authBind.Type = curAuthType
|
||||
authBind.TypeID = curAuthTypeID
|
||||
authBind.AuthID = openID
|
||||
if authDetail != nil {
|
||||
authBind.DetailData = string(utils.MustMarshal(authDetail))
|
||||
@@ -84,7 +89,7 @@ func (a *DefAuther) UnionFindAuthBind(curAuthType string, unionAuthTypeList []st
|
||||
authBindEx = &auth2.AuthBindEx{
|
||||
AuthBind: *authBind,
|
||||
}
|
||||
a.UnbindAuth(authBind.UserID, curAuthType, model.AdminName)
|
||||
a.UnbindAuth(authBind.UserID, curAuthType, curAuthTypeID, model.AdminName)
|
||||
err = a.AddAuthBind(authBindEx, model.AdminName) // 自动绑定
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
err = nil
|
||||
@@ -97,6 +102,7 @@ func (a *DefAuther) UnionFindAuthBind(curAuthType string, unionAuthTypeList []st
|
||||
authBindEx = &auth2.AuthBindEx{
|
||||
AuthBind: model.AuthBind{
|
||||
Type: curAuthType,
|
||||
TypeID: curAuthTypeID,
|
||||
AuthID: openID,
|
||||
AuthID2: unionID,
|
||||
},
|
||||
|
||||
@@ -27,7 +27,7 @@ func (a *QRCodeAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthB
|
||||
userQRInfo, err := api.DingDingQRCodeAPI.GetUserInfoByCode(code)
|
||||
if err == nil {
|
||||
globals.SugarLogger.Debugf("dingding qrcode VerifySecret code:%s, userQRInfo:%s", code, utils.Format4Output(userQRInfo, false))
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeQRCode, []string{AuthTypeStaff, AuthTypeQRCode}, userQRInfo.OpenID, userQRInfo.UnionID, userQRInfo); err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeQRCode, api.DingDingQRCodeAPI.GetAppID(), []string{AuthTypeStaff, AuthTypeQRCode}, userQRInfo.OpenID, userQRInfo.UnionID, userQRInfo); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
Name: userQRInfo.Nickname,
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func (a *StaffAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBi
|
||||
if err == nil {
|
||||
userDetail, err2 := api.DingDingAPI.GetUserDetail(userID.UserID)
|
||||
if err = err2; err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeStaff, []string{AuthTypeStaff, AuthTypeQRCode}, userID.UserID, utils.Interface2String(userDetail["unionid"]), userDetail); err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeStaff, api.DingDingQRCodeAPI.GetAppID(), []string{AuthTypeStaff, AuthTypeQRCode}, userID.UserID, utils.Interface2String(userDetail["unionid"]), userDetail); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
UserID2: userID.UserID,
|
||||
Mobile: utils.Interface2String(userDetail["mobile"]),
|
||||
|
||||
@@ -85,6 +85,6 @@ func (a *Auther) AddAuthBind(authBindEx *auth2.AuthBindEx, userName string) (err
|
||||
}
|
||||
|
||||
// 此函数为空
|
||||
func (a *Auther) UnbindAuth(userID, authType, userName string) (err error) {
|
||||
func (a *Auther) UnbindAuth(userID, authType, authTypeID, userName string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx,
|
||||
if err == nil {
|
||||
wxUserinfo, err2 := a.getAPI().SNSGetUserInfo(accessToken, openID)
|
||||
if err = err2; err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(a.authType, []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(a.authType, a.getAPI().GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
Name: wxUserinfo.NickName,
|
||||
Avatar: wxUserinfo.HeadImgURL,
|
||||
|
||||
@@ -42,7 +42,7 @@ func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBindEx *auth2.AuthB
|
||||
if err == nil {
|
||||
sessionKey := sessionInfo.SessionKey
|
||||
sessionInfo.SessionKey = ""
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeMini, []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative}, sessionInfo.OpenID, sessionInfo.UnionID, sessionInfo); err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeMini, getWxApp(appID).GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative}, sessionInfo.OpenID, sessionInfo.UnionID, sessionInfo); err == nil {
|
||||
authBindEx.UserData = sessionKey
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (a *MiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encryptedData
|
||||
if jsCode != "" {
|
||||
sessionInfo, err := getWxApp(appID).SNSCode2Session(jsCode)
|
||||
if err == nil {
|
||||
if authBindEx, err := a.UnionFindAuthBind(AuthTypeMini, []string{AuthTypeMini}, sessionInfo.OpenID, "", nil); err == nil {
|
||||
if authBindEx, err := a.UnionFindAuthBind(AuthTypeMini, getWxApp(appID).GetAppID(), []string{AuthTypeMini}, sessionInfo.OpenID, "", nil); err == nil {
|
||||
if authBindEx.UserID != authInfo.GetID() {
|
||||
return "", fmt.Errorf("jsCode与token不匹配")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user