- remove user2.ChangeMobile (use auth2.AddAuthBind instead)
This commit is contained in:
@@ -51,6 +51,8 @@ type IUser interface {
|
||||
|
||||
type IUserProvider interface {
|
||||
GetUser(authID, authIDType string) (user IUser)
|
||||
UpdateUserMobile(userID string, mobile string) (err error)
|
||||
UpdateUserEmail(userID string, email string) (err error)
|
||||
}
|
||||
|
||||
type CaptchaInfo struct {
|
||||
@@ -237,8 +239,14 @@ func AddAuthBind(authInfo *AuthInfo, newAuthInfo *AuthInfo) (err error) {
|
||||
return ErrAuthTypeAlreadyExist
|
||||
}
|
||||
RemoveUserInfo(newAuthInfo.Token)
|
||||
newAuthInfo.AuthBindInfo.UserID = authInfo.GetID()
|
||||
err = authers[newAuthInfo.AuthBindInfo.Type].AddAuthBind(newAuthInfo.AuthBindInfo, authInfo.GetName())
|
||||
if newAuthInfo.AuthBindInfo.Type == AuthTypeMobile {
|
||||
err = userProvider.UpdateUserMobile(authInfo.GetID(), newAuthInfo.AuthBindInfo.AuthID)
|
||||
} else if newAuthInfo.AuthBindInfo.Type == AuthTypeEmail {
|
||||
err = userProvider.UpdateUserEmail(authInfo.GetID(), newAuthInfo.AuthBindInfo.AuthID)
|
||||
} else {
|
||||
newAuthInfo.AuthBindInfo.UserID = authInfo.GetID()
|
||||
err = authers[newAuthInfo.AuthBindInfo.Type].AddAuthBind(newAuthInfo.AuthBindInfo, authInfo.GetName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,24 @@ func (*UserProvider) GetUser(authID, authIDType string) (user auth2.IUser) {
|
||||
return user
|
||||
}
|
||||
|
||||
func (*UserProvider) UpdateUserMobile(userID string, mobile string) (err error) {
|
||||
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
"Mobile": mobile,
|
||||
}, "admin", map[string]interface{}{
|
||||
"UserID": userID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (*UserProvider) UpdateUserEmail(userID string, email string) (err error) {
|
||||
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
"Email": email,
|
||||
}, "admin", map[string]interface{}{
|
||||
"UserID": userID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func init() {
|
||||
auth2.Init(userProvider)
|
||||
}
|
||||
@@ -77,21 +95,3 @@ func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, er
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func ChangeMobile2(ctx *jxcontext.Context, mobile, mobileVerifyCode string) (err error) {
|
||||
authInfo, err := ctx.GetV2AuthInfo()
|
||||
if err == nil {
|
||||
mobileAuth, err2 := auth2.Login(auth2.AuthTypeMobile, mobile, auth2.UserIDMobile, mobileVerifyCode)
|
||||
if err = err2; err == nil {
|
||||
if mobileAuth.IUser != nil && authInfo.GetID() != mobileAuth.GetID() {
|
||||
return errors.New("手机号已经存在")
|
||||
}
|
||||
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
"Mobile": mobile,
|
||||
}, ctx.GetUserName(), map[string]interface{}{
|
||||
"UserID": authInfo.GetID(),
|
||||
})
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -123,6 +123,7 @@ func (ctx *Context) GetLoginInfo() IAuther {
|
||||
}
|
||||
|
||||
func (ctx *Context) GetV2AuthInfo() (authInfo *auth2.AuthInfo, err error) {
|
||||
globals.SugarLogger.Debugf("GetV2AuthInfo, authInfo:%s", utils.Format4Output(authInfo, false))
|
||||
authInfo, ok := ctx.userInfo.(*auth2.AuthInfo)
|
||||
if ok {
|
||||
return authInfo, nil
|
||||
|
||||
Reference in New Issue
Block a user