RegisterUser支持注册用户时,不指定手机号

This commit is contained in:
gazebo
2019-10-21 15:14:34 +08:00
parent d24b8ea53d
commit bed2d85833
4 changed files with 49 additions and 26 deletions

View File

@@ -115,26 +115,45 @@ func init() {
}
func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVerifyCode string, inAuthInfo *auth2.AuthInfo) (outAuthInfo *auth2.AuthInfo, err error) {
mobileAuth, err2 := auth2.Login(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
if err = err2; err == nil {
if !mobileAuth.IsUserEmpty() {
var mobileAuth *auth2.AuthInfo
if mobileVerifyCode != "" {
mobileAuth, err = auth2.Login(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
if err != nil {
return nil, err
}
if mobileAuth != nil && !mobileAuth.IsUserEmpty() {
return nil, jsonerr.New(mobileAuth, model.ErrCodeJsonUserAlreadyExist)
}
} else {
if inAuthInfo == nil {
return nil, fmt.Errorf("短信验证码与其它认证方式至少要指定一种")
}
user.Mobile = nil
}
createName := ctx.GetRealRemoteIP()
authType := auth2.AuthTypeMobile
if inAuthInfo != nil {
user.Type = model.UserTypeConsumer
if inAuthInfo.AuthBindInfo.Type == dingding.AuthTypeStaff {
user.Type |= model.UserTypeOperator
} else {
user.Type |= model.UserTypeStoreBoss
}
if err = CreateUser(user, utils.LimitUTF8StringLen(ctx.GetRealRemoteIP()+","+inAuthInfo.GetAuthID(), 32)); err == nil {
userProvider.UpdateLastLogin(user.GetID(), inAuthInfo.GetAuthType(), ctx.GetRealRemoteIP())
TryAddStoreBossRole4User(ctx, user)
createName += "," + inAuthInfo.GetAuthID()
authType = inAuthInfo.GetAuthType()
}
if err = CreateUser(user, utils.LimitUTF8StringLen(createName, 32)); err == nil {
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
TryAddStoreBossRole4User(ctx, user)
if mobileAuth != nil {
if outAuthInfo, err = auth2.BindUser(mobileAuth, user); err == nil && inAuthInfo != nil {
err = auth2.AddAuthBind(&outAuthInfo.UserBasic, inAuthInfo)
}
} else if dao.IsDuplicateError(err) {
err = auth2.ErrUserID2AlreadyExist
} else {
outAuthInfo, err = auth2.BindUser(inAuthInfo, user)
}
} else if dao.IsDuplicateError(err) {
err = auth2.ErrUserID2AlreadyExist
}
return outAuthInfo, err
}