- refactor defauther.UnionFindAuthBind
This commit is contained in:
@@ -14,9 +14,9 @@ type DefAuther struct {
|
||||
|
||||
// 此函数为空
|
||||
func (a *DefAuther) AddAuthBind(authBindEx *auth2.AuthBindEx, userName string) (err error) {
|
||||
dao.WrapAddIDCULDEntity(authBindEx, userName)
|
||||
dao.WrapAddIDCULDEntity(&authBindEx.AuthBind, userName)
|
||||
authBindEx.Status = model.AuthBindStatusNormal
|
||||
err = dao.CreateEntity(nil, authBindEx.AuthBind)
|
||||
err = dao.CreateEntity(nil, &authBindEx.AuthBind)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -37,3 +37,43 @@ func (a *DefAuther) SendVerifyCode(authID string) error {
|
||||
func (a *DefAuther) Logout(authInfo *auth2.AuthInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 此函数用于联合(通过unionID)查找用户
|
||||
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 unionID != "" { // 且有unionID
|
||||
var authBindList []*model.AuthBind
|
||||
if authBindList, err = dao.GetAuthBindsByAuthID2(db, unionID, unionAuthTypeList); err == nil && len(authBindList) > 0 { // 通过unionID找到至少一个认证方式
|
||||
authBind = authBindList[0]
|
||||
authBind.Type = curAuthType
|
||||
authBind.AuthID = openID
|
||||
if authDetail != nil {
|
||||
authBind.DetailData = string(utils.MustMarshal(authDetail))
|
||||
}
|
||||
authBindEx = &auth2.AuthBindEx{
|
||||
AuthBind: *authBind,
|
||||
}
|
||||
err = a.AddAuthBind(authBindEx, "admin") // 自动绑定
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
err = nil
|
||||
}
|
||||
} else {
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
if err == nil && authBindEx == nil { //如果没有报错,且没有找到一个认证方式,创建无用户(UserID为空)的认证方式
|
||||
authBindEx = &auth2.AuthBindEx{
|
||||
AuthBind: model.AuthBind{
|
||||
Type: curAuthType,
|
||||
AuthID: openID,
|
||||
AuthID2: unionID,
|
||||
},
|
||||
}
|
||||
if authDetail != nil {
|
||||
authBindEx.DetailData = string(utils.MustMarshal(authDetail))
|
||||
}
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user