- set correct authIDType when calling auth2.Login

This commit is contained in:
gazebo
2019-03-04 17:50:16 +08:00
parent 3e79e8a99b
commit 083f9ccbcf
3 changed files with 11 additions and 4 deletions

View File

@@ -120,9 +120,9 @@ func CreateAuthInfo(user IUser, authBindInfo *model.AuthBind, userData interface
UserData: userData, UserData: userData,
} }
if user != nil { if user != nil {
globals.SugarLogger.Debugf("CreateAuthInfo id:%s, id2:%s, authBindInfo:%s, authInfo:%s", authInfo.GetID(), authInfo.GetID2(), authInfo.GetMobile(), utils.Format4Output(authBindInfo, true), utils.Format4Output(authInfo, true)) globals.SugarLogger.Debugf("CreateAuthInfo id:%s, id2:%s, authInfo:%s", authInfo.GetID(), authInfo.GetID2(), authInfo.GetMobile(), utils.Format4Output(authInfo, true))
} else { } else {
globals.SugarLogger.Debugf("CreateAuthInfo authBindInfo:%s, authInfo:%s", utils.Format4Output(authBindInfo, true), utils.Format4Output(authInfo, true)) globals.SugarLogger.Debugf("CreateAuthInfo authInfo:%s", utils.Format4Output(authInfo, true))
} }
SetUserInfo(token, authInfo, DefTokenDuration) SetUserInfo(token, authInfo, DefTokenDuration)
return authInfo return authInfo
@@ -163,6 +163,8 @@ func SendVerifyCode(authToken, captchaID, captchaValue, authID string) (err erro
} }
// 账号密码时authIDType可能是UserIDID,UserIDID2,UserIDMobile,UserIDEmailauthSecret是密码的sha1 // 账号密码时authIDType可能是UserIDID,UserIDID2,UserIDMobile,UserIDEmailauthSecret是密码的sha1
// mobile或email登录时authIDType必须相应为UserIDMobile,UserIDEmail
// 其它登录时authIDType无用
// 邮箱时如果允许authIDType是UserIDEmailauthSecret是验证码的sha1 // 邮箱时如果允许authIDType是UserIDEmailauthSecret是验证码的sha1
// 手机时如果允许authIDType是UserIDMobileauthSecret是验证码的sha1 // 手机时如果允许authIDType是UserIDMobileauthSecret是验证码的sha1
// 公众号登录authIDTypeD是UserIDEmptyauthSecret是code这个函数是被微信的回调调用不是直接被客户端调用 // 公众号登录authIDTypeD是UserIDEmptyauthSecret是code这个函数是被微信的回调调用不是直接被客户端调用

View File

@@ -44,7 +44,7 @@ func RegisterUser(user *model.User, mobileVerifyCode string, inAuthInfo *auth2.A
if user == nil || user.UserID2 == "" || user.Name == "" || user.Mobile == "" { if user == nil || user.UserID2 == "" || user.Name == "" || user.Mobile == "" {
return nil, model.ErrCodeGeneralFailed, ErrUserIDAndNameMustGiven return nil, model.ErrCodeGeneralFailed, ErrUserIDAndNameMustGiven
} }
mobileAuth, err2 := auth2.Login(auth2.AuthTypeMobile, user.Mobile, auth2.UserIDNone, mobileVerifyCode) mobileAuth, err2 := auth2.Login(auth2.AuthTypeMobile, user.Mobile, auth2.UserIDMobile, mobileVerifyCode)
if err = err2; err == nil { if err = err2; err == nil {
if mobileAuth.IUser != nil { if mobileAuth.IUser != nil {
return nil, model.ErrCodeUserAlreadyExist, auth2.ErrUserMobileAlreadyExist return nil, model.ErrCodeUserAlreadyExist, auth2.ErrUserMobileAlreadyExist
@@ -78,7 +78,7 @@ func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, er
func ChangeMobile2(ctx *jxcontext.Context, mobile, mobileVerifyCode string) (err error) { func ChangeMobile2(ctx *jxcontext.Context, mobile, mobileVerifyCode string) (err error) {
authInfo, err := ctx.GetV2AuthInfo() authInfo, err := ctx.GetV2AuthInfo()
if err == nil { if err == nil {
mobileAuth, err2 := auth2.Login(auth2.AuthTypeMobile, mobile, auth2.UserIDNone, mobileVerifyCode) mobileAuth, err2 := auth2.Login(auth2.AuthTypeMobile, mobile, auth2.UserIDMobile, mobileVerifyCode)
if err = err2; err == nil { if err = err2; err == nil {
if mobileAuth.IUser != nil && authInfo.GetID() != mobileAuth.GetID() { if mobileAuth.IUser != nil && authInfo.GetID() != mobileAuth.GetID() {
return errors.New("手机号已经存在") return errors.New("手机号已经存在")

View File

@@ -60,6 +60,11 @@ func (c *Auth2Controller) SendVerifyCode() {
// @router /Login [post] // @router /Login [post]
func (c *Auth2Controller) Login() { func (c *Auth2Controller) Login() {
c.callLogin(func(params *tAuth2LoginParams) (retVal interface{}, errCode string, err error) { c.callLogin(func(params *tAuth2LoginParams) (retVal interface{}, errCode string, err error) {
if params.AuthType == auth2.AuthTypeMobile {
params.AuthIDType = auth2.UserIDMobile
} else if params.AuthType == auth2.AuthTypeEmail {
params.AuthIDType = auth2.UserIDEmail
}
retVal, err = auth2.Login(params.AuthType, params.AuthID, params.AuthIDType, params.AuthSecret) retVal, err = auth2.Login(params.AuthType, params.AuthID, params.AuthIDType, params.AuthSecret)
return retVal, "", err return retVal, "", err
}) })