- remove user2.ChangeMobile (use auth2.AddAuthBind instead)
This commit is contained in:
@@ -51,6 +51,8 @@ type IUser interface {
|
|||||||
|
|
||||||
type IUserProvider interface {
|
type IUserProvider interface {
|
||||||
GetUser(authID, authIDType string) (user IUser)
|
GetUser(authID, authIDType string) (user IUser)
|
||||||
|
UpdateUserMobile(userID string, mobile string) (err error)
|
||||||
|
UpdateUserEmail(userID string, email string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CaptchaInfo struct {
|
type CaptchaInfo struct {
|
||||||
@@ -237,8 +239,14 @@ func AddAuthBind(authInfo *AuthInfo, newAuthInfo *AuthInfo) (err error) {
|
|||||||
return ErrAuthTypeAlreadyExist
|
return ErrAuthTypeAlreadyExist
|
||||||
}
|
}
|
||||||
RemoveUserInfo(newAuthInfo.Token)
|
RemoveUserInfo(newAuthInfo.Token)
|
||||||
newAuthInfo.AuthBindInfo.UserID = authInfo.GetID()
|
if newAuthInfo.AuthBindInfo.Type == AuthTypeMobile {
|
||||||
err = authers[newAuthInfo.AuthBindInfo.Type].AddAuthBind(newAuthInfo.AuthBindInfo, authInfo.GetName())
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,24 @@ func (*UserProvider) GetUser(authID, authIDType string) (user auth2.IUser) {
|
|||||||
return user
|
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() {
|
func init() {
|
||||||
auth2.Init(userProvider)
|
auth2.Init(userProvider)
|
||||||
}
|
}
|
||||||
@@ -77,21 +95,3 @@ func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, er
|
|||||||
}
|
}
|
||||||
return nil, err
|
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) {
|
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)
|
authInfo, ok := ctx.userInfo.(*auth2.AuthInfo)
|
||||||
if ok {
|
if ok {
|
||||||
return authInfo, nil
|
return authInfo, nil
|
||||||
|
|||||||
@@ -52,18 +52,3 @@ func (c *User2Controller) GetBindAuthInfo() {
|
|||||||
return retVal, "", err
|
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -983,6 +983,14 @@ func init() {
|
|||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Params: nil})
|
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.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "RegisterUser",
|
Method: "RegisterUser",
|
||||||
|
|||||||
Reference in New Issue
Block a user