diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index 1b920ed26..b1d671371 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -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 } diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index b80dad3ec..f8d438746 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -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 -} diff --git a/business/jxutils/jxcontext/jxcontext.go b/business/jxutils/jxcontext/jxcontext.go index 3ff733c7a..ee144e7fe 100644 --- a/business/jxutils/jxcontext/jxcontext.go +++ b/business/jxutils/jxcontext/jxcontext.go @@ -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 diff --git a/controllers/cms_user2.go b/controllers/cms_user2.go index 5c16d2aac..4866b0743 100644 --- a/controllers/cms_user2.go +++ b/controllers/cms_user2.go @@ -52,18 +52,3 @@ func (c *User2Controller) GetBindAuthInfo() { return retVal, "", err }) } - -// @Title 修改手机号 -// @Description 修改手机号 -// @Param token header string true "认证token" -// @Param mobile query string true "新手机号" -// @Param mobileVerifyCode query string true "手机验证码(通过auth2.SendVerifyCode获得)" -// @Success 200 {object} controllers.CallResult -// @Failure 200 {object} controllers.CallResult -// @router /ChangeMobile [put] -func (c *User2Controller) ChangeMobile() { - c.callChangeMobile(func(params *tUser2ChangeMobileParams) (retVal interface{}, errCode string, err error) { - err = cms.ChangeMobile2(params.Ctx, params.Mobile, params.MobileVerifyCode) - return retVal, "", err - }) -} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index acc2fbbd6..bf6028cb2 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -983,6 +983,14 @@ func init() { MethodParams: param.Make(), Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"], + beego.ControllerComments{ + Method: "GetBindAuthInfo", + Router: `/GetBindAuthInfo`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"], beego.ControllerComments{ Method: "RegisterUser",