- 认证通过且通过手机(或邮箱)能找到用户,在没有相应认证方式的情况下,自动绑定此认证方式
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
|
||||
|
||||
@@ -53,6 +53,10 @@ func (a *DefAuther) Logout(authInfo *auth2.AuthInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *DefAuther) GetUserType() (userType int8) {
|
||||
return model.UserTypeConsumer
|
||||
}
|
||||
|
||||
// 此函数用于联合(通过unionID)查找用户
|
||||
func (a *DefAuther) UnionFindAuthBind(curAuthType string, unionAuthTypeList []string, openID, unionID string, authDetail interface{}) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
db := dao.GetDB()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dingding
|
||||
|
||||
const (
|
||||
AuthTypeDingDing = "dingding"
|
||||
AuthTypeStaff = "ddstaff" // 钉钉企业登录
|
||||
AuthTypeQRCode = "ddqrcode"
|
||||
AuthTypeStaff = "ddstaff" // 钉钉企业登录
|
||||
AuthTypeQRCode = "ddqrcode"
|
||||
)
|
||||
|
||||
@@ -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{AuthTypeDingDing, AuthTypeStaff, AuthTypeQRCode}, userQRInfo.OpenID, userQRInfo.UnionID, userQRInfo); err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeQRCode, []string{AuthTypeStaff, AuthTypeQRCode}, userQRInfo.OpenID, userQRInfo.UnionID, userQRInfo); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
Name: userQRInfo.Nickname,
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
@@ -28,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{AuthTypeDingDing, AuthTypeStaff, AuthTypeQRCode}, userID.UserID, utils.Interface2String(userDetail["unionid"]), userDetail); err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeStaff, []string{AuthTypeStaff, AuthTypeQRCode}, userID.UserID, utils.Interface2String(userDetail["unionid"]), userDetail); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
UserID2: userID.UserID,
|
||||
Mobile: utils.Interface2String(userDetail["mobile"]),
|
||||
@@ -40,3 +41,7 @@ func (a *StaffAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBi
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
|
||||
func (a *StaffAuther) GetUserType() (userType int8) {
|
||||
return model.UserTypeOperator
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
@@ -68,3 +69,7 @@ func (a *Auther) getAPI() *weixinapi.API {
|
||||
}
|
||||
return api.WeixinAPI
|
||||
}
|
||||
|
||||
func (a *Auther) GetUserType() (userType int8) {
|
||||
return model.UserTypeStoreBoss
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
@@ -57,6 +58,10 @@ func (a *MiniAuther) DecryptData(authInfo *auth2.AuthInfo, encryptedData, iv str
|
||||
return base64.StdEncoding.EncodeToString(decryptedData), nil
|
||||
}
|
||||
|
||||
func (a *MiniAuther) GetUserType() (userType int8) {
|
||||
return model.UserTypeStoreBoss
|
||||
}
|
||||
|
||||
func ProxySNSCode2Session(jsCode string) (sessionInfo *weixinapi.SessionInfo, err error) {
|
||||
miniApi := api.WeixinMiniAPI
|
||||
list := strings.Split(jsCode, ",")
|
||||
|
||||
@@ -69,6 +69,24 @@ func (*UserProvider) UpdateUserEmail(userID string, email string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (*UserProvider) UpdateUserType(userID string, userTypeMask int8, updateType int) (err error) {
|
||||
db := dao.GetDB()
|
||||
user := &model.User{
|
||||
UserID: userID,
|
||||
}
|
||||
if err = dao.GetEntity(db, user, "UserID"); err == nil {
|
||||
if updateType == auth2.UpdateUserTypeAdd {
|
||||
user.Type |= userTypeMask
|
||||
} else if updateType == auth2.UpdateUserTypeDelete {
|
||||
user.Type &= ^userTypeMask
|
||||
} else {
|
||||
user.Type = userTypeMask
|
||||
}
|
||||
_, err = dao.UpdateEntity(db, user, "Type")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// func (*UserProvider) CreateUser(userID2, mobile, email, name string) (user auth2.IUser, err error) {
|
||||
// realUser := &model.User{
|
||||
// UserID2: userID2,
|
||||
|
||||
@@ -33,6 +33,7 @@ func (c *User2Controller) RegisterUser() {
|
||||
}
|
||||
if err == nil {
|
||||
if err = jxutils.Strings2Objs(params.Payload, &user); err == nil {
|
||||
user.Type = 0
|
||||
retVal, err = cms.RegisterUser(&user, params.MobileVerifyCode, inAuthInfo)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user