예제 #1
0
        public JsonResult RegisterUser(string username, string password, string mobile, string email, string checkCode, long introducer = 0)
        {
            var siteset = SiteSettings;

            if (siteset.RegisterEmailRequired)
            {
                if (string.IsNullOrWhiteSpace(email))
                {
                    return(Json(new { success = false, msg = "错误的电子邮箱地址" }));
                }
            }
            if (siteset.MobileVerifOpen)
            {
                if (string.IsNullOrWhiteSpace(mobile))
                {
                    return(Json(new { success = false, msg = "错误的手机号码" }));
                }
            }

            if (StringHelper.GetStringLength(username) > CommonModel.CommonConst.MEMBERNAME_LENGTH)
            {
                var unicodeChar = CommonModel.CommonConst.MEMBERNAME_LENGTH / 2;

                return(Json(new { success = false, msg = "用户名最大长度为" + CommonModel.CommonConst.MEMBERNAME_LENGTH + "位," + unicodeChar + "个中文字符" }));
            }

            var cacheCheckCode = Session[CHECK_CODE_KEY] as string;

            if (cacheCheckCode == null || string.IsNullOrEmpty(checkCode) || checkCode.ToLower() != cacheCheckCode.ToLower())
            {
                return(Json(new { success = false, msg = "验证码错误" }));
            }

            var member = _iMemberService.Register(username, password, (int)PlatformType.PC, mobile, email, introducer);

            if (member != null)
            {
                //自动登录
                _iMemberService.Login(username, password);

                base.SetUserLoginCookie(member.Id);

                Session.Remove(CHECK_CODE_KEY);
                if (!string.IsNullOrEmpty(mobile))
                {
                    Core.Cache.Remove(CacheKeyCollection.MemberPluginCheck(mobile, "Himall.Plugin.Message.SMS"));
                }
            }
            //TODO:ZJT  在用户注册的时候,检查此用户是否存在OpenId是否存在红包,存在则添加到用户预存款里
            _iBonusService.DepositToRegister(member.Id);
            //用户注册的时候,检查是否开启注册领取优惠券活动,存在自动添加到用户预存款里
            int num = CouponApplication.RegisterSendCoupon(member.Id, member.UserName);

            return(Json(new { success = true, memberId = member.Id, num = num }));
        }
예제 #2
0
        public JsonResult Index(string serviceProvider, string openId, string username, string password, string checkCode, string mobilecheckCode,
                                string headimgurl, long introducer = 0, string unionid = null, string sex = null,
                                string city = null, string province = null, string country = null, string nickName = null, string email = "", string emailcheckCode = "")
        {
            var    mobilepluginId  = "Himall.Plugin.Message.SMS";
            var    emailpluginId   = "Himall.Plugin.Message.Email";
            string systemCheckCode = Session[CHECK_CODE_KEY] as string;

            if (systemCheckCode.ToLower() != checkCode.ToLower())
            {
                throw new Core.HimallException("验证码错误");
            }

            if (Core.Helper.ValidateHelper.IsMobile(username))
            {
                var cache     = CacheKeyCollection.MemberPluginCheck(username, mobilepluginId);
                var cacheCode = Core.Cache.Get <string>(cache);

                if (string.IsNullOrEmpty(mobilecheckCode) || mobilecheckCode.ToLower() != cacheCode.ToLower())
                {
                    throw new Core.HimallException("手机验证码错误");
                }
            }

            if (!string.IsNullOrEmpty(email) && Core.Helper.ValidateHelper.IsMobile(email))
            {
                var cache     = CacheKeyCollection.MemberPluginCheck(username, emailpluginId);
                var cacheCode = Core.Cache.Get <string>(cache);

                if (string.IsNullOrEmpty(emailcheckCode) || emailcheckCode.ToLower() != cacheCode.ToLower())
                {
                    throw new Core.HimallException("手机验证码错误");
                }
            }

            headimgurl = System.Web.HttpUtility.UrlDecode(headimgurl);
            nickName   = System.Web.HttpUtility.UrlDecode(nickName);
            province   = System.Web.HttpUtility.UrlDecode(province);
            city       = System.Web.HttpUtility.UrlDecode(city);
            Entities.MemberInfo member;
            var mobile = "";

            if (Core.Helper.ValidateHelper.IsMobile(username))
            {
                mobile = username;
            }
            var platform = PlatformType.GetHashCode();//注册终端来源

            if (!string.IsNullOrWhiteSpace(serviceProvider) && !string.IsNullOrWhiteSpace(openId))
            {
                OAuthUserModel userModel = new OAuthUserModel
                {
                    UserName      = username,
                    Password      = password,
                    LoginProvider = serviceProvider,
                    OpenId        = openId,
                    Headimgurl    = headimgurl,
                    Sex           = sex,
                    NickName      = nickName,
                    Email         = email,
                    UnionId       = unionid,
                    introducer    = introducer,
                    Province      = province,
                    City          = city,
                    Platform      = platform,
                    SpreadId      = CurrentSpreadId
                };
                member = _iMemberService.Register(userModel);
            }
            else
            {
                member = _iMemberService.Register(username, password, platform, mobile, email, introducer, spreadId: CurrentSpreadId);
            }
            if (member != null)
            {
                Session.Remove(CHECK_CODE_KEY);
                MessageHelper helper = new MessageHelper();
                helper.ClearErrorTimes(member.UserName);
                if (!string.IsNullOrEmpty(email))
                {
                    helper.ClearErrorTimes(member.Email);
                }
                ClearDistributionSpreadCookie();
            }
            //TODO:ZJT  在用户注册的时候,检查此用户是否存在OpenId是否存在红包,存在则添加到用户预存款里
            _iBonusService.DepositToRegister(member.Id);
            //用户注册的时候,检查是否开启注册领取优惠券活动,存在自动添加到用户预存款里
            int num = CouponApplication.RegisterSendCoupon(member.Id, member.UserName);

            base.SetUserLoginCookie(member.Id);
            Application.MemberApplication.UpdateLastLoginDate(member.Id);
            _iMemberService.AddIntegel(member); //给用户加积分//执行登录后初始化相关操作
            return(Json <dynamic>(success: true, data: new { memberId = member.Id, num = num }));
        }
예제 #3
0
 public static void DepositToRegister(long userid)
 {
     _iBonusService.DepositToRegister(userid);
 }