Example #1
0
        public bool Register(params Action <IUser>[] listeners)
        {
            if (!this._userCode.IsMobileNo())
            {
                Alert((ResultType)409, "请输入正确的手机号码");
                return(false);
            }
            if (!AppConfig.DisableMobileVerification)
            {
                if (string.IsNullOrEmpty(_smsCode))
                {
                    Alert((ResultType)409, "短信验证码不能为空");
                    return(false);
                }
                SmsValidateProvider validate = new SmsValidateProvider(this._userCode, Entities.SmsValidateType.注册);
                if (!validate.ValidateCode(this._smsCode))
                {
                    Alert(validate.PromptInfo);
                    return(false);
                }
            }
            UserCreationProvider userCreation = new UserCreationProvider(this._userCode, this._password, this._refereeCode);

            if (listeners != null || listeners.Length > 0)
            {
                foreach (Action <IUser> lst in listeners)
                {
                    userCreation.Success += lst;
                }
            }
            if (!userCreation.AddUser())
            {
                Alert(userCreation.PromptInfo);
                return(false);
            }
            return(true);
        }
Example #2
0
        public bool Register()
        {
            string[] array = new string[2];
            string   plainText;

            if (!xUtils.RsaDecrypt(_model.AuthCode, out plainText))
            {
                Alert("OpenID解密失败");
                return(false);
            }
            int pos = plainText.IndexOf('_');

            array[0] = plainText.Substring(0, pos);
            array[1] = plainText.Substring(pos + 1);
            long timestamp;

            if (!long.TryParse(array[0], out timestamp))
            {
                Alert("OpenID解密失败");
                return(false);
            }
            long currentTime = xUtils.GetCurrentTimeStamp();

            if (currentTime - timestamp > 120)
            {
                Alert("请求已过期");
                return(false);
            }
            string openID = array[1];
            SmsValidateProvider smsValidate = new SmsValidateProvider(_model.MobileNo, SmsValidateType.绑定手机号);

            if (!smsValidate.ValidateCode(_model.ValidateCode))
            {
                Alert(smsValidate.PromptInfo);
                return(false);
            }
            var fac = UserModuleFactory.GetUserModuleInstance();

            if (fac == null)
            {
                Alert("系统模块异常");
                return(false);
            }
            if (!Enum.TryParse(_model.Platform, true, out ThirdpartyLoginPlatform platform))
            {
                Alert($"无效的第三方登录平台[{_model.Platform}]");
                return(false);
            }
            UserVoucherType uvt            = (UserVoucherType)platform;
            IUser           thirdpartyUser = fac.GetUserByVoucher(openID, uvt);

            if (thirdpartyUser == null)
            {
                IUser user = fac.GetUserByMobileno(_model.MobileNo);
                if (user == null)
                {
                    var voucher = fac.GetVoucherObject();
                    voucher.AllowLogin  = true;
                    voucher.IsValid     = true;
                    voucher.Status      = 1;
                    voucher.UserCode    = _model.MobileNo;
                    voucher.VoucherType = UserVoucherType.手机号;
                    UserCreationProvider ucp = new UserCreationProvider(openID, null, _model.RefereeCode, uvt);
                    ucp.Vouchers.Add(voucher);
                    if (!ucp.AddUser(_model.NickName ?? xUtils.GetDefaultUserName(_model.MobileNo), _model.Avatar))
                    {
                        Alert(ucp.PromptInfo);
                        return(false);
                    }
                    user = ucp.User;
                }
                else
                {
                    var voucher = fac.GetVoucherObject();
                    voucher.AllowLogin  = true;
                    voucher.IsValid     = true;
                    voucher.Status      = 1;
                    voucher.UserCode    = openID;
                    voucher.VoucherType = uvt;
                    if (!voucher.Save(user.UserId))
                    {
                        Alert((ResultType)503, "已有账号绑定第三方登录失败");
                        return(false);
                    }
                    user.Refresh();
                }
                this.User = user;
            }
            else
            {
                var thirdpartyVoucher = thirdpartyUser.Vouchers?.Find(it => it.VoucherType == uvt);
                if (thirdpartyVoucher != null)
                {
                    Alert((ResultType)409, $"该账号[{_model.MobileNo}]已绑定{platform.GetDisplayText()}");
                    return(false);
                }
                var voucher = fac.GetVoucherObject();
                voucher.AllowLogin  = true;
                voucher.IsValid     = true;
                voucher.Status      = 1;
                voucher.UserCode    = _model.MobileNo;
                voucher.VoucherType = UserVoucherType.手机号;
                if (!voucher.Save(thirdpartyUser.UserId))
                {
                    Alert((ResultType)503, "已有账号绑定第三方登录失败");
                    return(false);
                }
                thirdpartyUser.Refresh();
                this.User = thirdpartyUser;
            }
            return(true);
        }