예제 #1
0
 /// <summary>
 /// 创建用户
 /// </summary>
 /// <returns></returns>
 public static int CreateUser(UserInfo userInfo)
 {
     return BrnShop.Core.BSPData.RDBS.CreateUser(userInfo);
 }
예제 #2
0
 /// <summary>
 /// 更新用户
 /// </summary>
 /// <returns></returns>
 public static void UpdateUser(UserInfo userInfo)
 {
     BrnShop.Core.BSPData.RDBS.UpdateUser(userInfo);
     if (_usernosql != null)
         _usernosql.UpdateUser(userInfo);
 }
예제 #3
0
 /// <summary>
 /// 创建用户
 /// </summary>
 /// <returns></returns>
 public static int CreateUser(UserInfo userInfo)
 {
     return BrnShop.Data.Users.CreateUser(userInfo);
 }
예제 #4
0
        /// <summary>
        /// 从IDataReader创建UserInfo
        /// </summary>
        public static UserInfo BuildUserFromReader(IDataReader reader)
        {
            UserInfo userInfo = new UserInfo();

            userInfo.Uid = TypeHelper.ObjectToInt(reader["uid"]);
            userInfo.UserName = reader["username"].ToString();
            userInfo.Email = reader["email"].ToString();
            userInfo.Mobile = reader["mobile"].ToString();
            userInfo.Password = reader["password"].ToString();
            userInfo.UserRid = TypeHelper.ObjectToInt(reader["userrid"]);
            userInfo.AdminGid = TypeHelper.ObjectToInt(reader["admingid"]);
            userInfo.NickName = reader["nickname"].ToString();
            userInfo.Avatar = reader["avatar"].ToString();
            userInfo.PayCredits = TypeHelper.ObjectToInt(reader["paycredits"]);
            userInfo.RankCredits = TypeHelper.ObjectToInt(reader["rankcredits"]);
            userInfo.VerifyEmail = TypeHelper.ObjectToInt(reader["verifyemail"]);
            userInfo.VerifyMobile = TypeHelper.ObjectToInt(reader["verifymobile"]);
            userInfo.LiftBanTime = TypeHelper.ObjectToDateTime(reader["liftbantime"]);
            userInfo.Salt = reader["salt"].ToString();
            userInfo.LastVisitTime = TypeHelper.ObjectToDateTime(reader["lastvisittime"]);
            userInfo.LastVisitIP = reader["lastvisitip"].ToString();
            userInfo.LastVisitRgId = TypeHelper.ObjectToInt(reader["lastvisitrgid"]);
            userInfo.RegisterTime = TypeHelper.ObjectToDateTime(reader["registertime"]);
            userInfo.RegisterIP = reader["registerip"].ToString();
            userInfo.RegisterRgId = TypeHelper.ObjectToInt(reader["registerrgid"]);
            userInfo.Gender = TypeHelper.ObjectToInt(reader["gender"]);
            userInfo.RealName = reader["realname"].ToString();
            userInfo.Bday = TypeHelper.ObjectToDateTime(reader["bday"]);
            userInfo.IdCard = reader["idcard"].ToString();
            userInfo.RegionId = TypeHelper.ObjectToInt(reader["regionid"]);
            userInfo.Address = reader["address"].ToString();
            userInfo.Bio = reader["bio"].ToString();

            return userInfo;
        }
예제 #5
0
 /// <summary>
 /// 更新用户
 /// </summary>
 /// <returns></returns>
 public static void UpdateUser(UserInfo userInfo)
 {
     BrnShop.Data.Users.UpdateUser(userInfo);
 }
예제 #6
0
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <returns></returns>
        public int CreateUser(UserInfo userInfo)
        {
            DbParameter[] parms = {
                                       GenerateInParam("@username",SqlDbType.NChar,20,userInfo.UserName),
                                       GenerateInParam("@email",SqlDbType.Char,50,userInfo.Email),
                                       GenerateInParam("@mobile",SqlDbType.Char,15,userInfo.Mobile),
                                       GenerateInParam("@password",SqlDbType.Char,32,userInfo.Password),
                                       GenerateInParam("@userrid",SqlDbType.SmallInt,2,userInfo.UserRid),
                                       GenerateInParam("@admingid",SqlDbType.SmallInt,2,userInfo.AdminGid),
                                       GenerateInParam("@nickname",SqlDbType.NChar,20,userInfo.NickName),
                                       GenerateInParam("@avatar",SqlDbType.Char,40,userInfo.Avatar),
                                       GenerateInParam("@paycredits",SqlDbType.Int,4,userInfo.PayCredits),
                                       GenerateInParam("@rankcredits",SqlDbType.Int,4,userInfo.RankCredits),
                                       GenerateInParam("@verifyemail",SqlDbType.TinyInt,1,userInfo.VerifyEmail),
                                       GenerateInParam("@verifymobile",SqlDbType.TinyInt,1,userInfo.VerifyMobile),
                                       GenerateInParam("@liftbantime",SqlDbType.DateTime,8,userInfo.LiftBanTime),
                                       GenerateInParam("@salt",SqlDbType.NChar,6,userInfo.Salt),
                                       GenerateInParam("@lastvisittime",SqlDbType.DateTime,8,userInfo.LastVisitTime),
                                       GenerateInParam("@lastvisitip",SqlDbType.Char,15,userInfo.LastVisitIP),
                                       GenerateInParam("@lastvisitrgid",SqlDbType.SmallInt,2,userInfo.LastVisitRgId),
                                       GenerateInParam("@registertime",SqlDbType.DateTime,8,userInfo.RegisterTime),
                                       GenerateInParam("@registerip",SqlDbType.Char,15,userInfo.RegisterIP),
                                       GenerateInParam("@registerrgid",SqlDbType.SmallInt,2,userInfo.RegisterRgId),
                                       GenerateInParam("@gender",SqlDbType.TinyInt,1,userInfo.Gender),
                                       GenerateInParam("@realname",SqlDbType.NVarChar,10,userInfo.RealName),
                                       GenerateInParam("@bday",SqlDbType.DateTime,8,userInfo.Bday),
                                       GenerateInParam("@idcard",SqlDbType.VarChar,18,userInfo.IdCard),
                                       GenerateInParam("@regionid",SqlDbType.SmallInt,2,userInfo.RegionId),
                                       GenerateInParam("@address",SqlDbType.NVarChar,150,userInfo.Address),
                                       GenerateInParam("@bio",SqlDbType.NVarChar,300,userInfo.Bio)
                                   };

            return TypeHelper.ObjectToInt(RdbsHelper.ExecuteScalar(CommandType.StoredProcedure,
                                                                      string.Format("{0}createuser", RdbsHelper.RdbsTablePre),
                                                                      parms), -1);
        }
예제 #7
0
        /// <summary>
        /// 发放注册积分
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="verifyTime">注册时间</param>
        public static void SendRegisterCredits(ref UserInfo userInfo, DateTime registerTime)
        {
            if (_creditconfiginfo.RegisterPayCredits > 0 || _creditconfiginfo.RegisterRankCredits > 0)
            {
                int surplusPayCredits = GetDaySurplusPayCredits(userInfo.Uid, registerTime.Date);
                int surplusRankCredits = GetDaySurplusRankCredits(userInfo.Uid, registerTime.Date);
                if (surplusPayCredits == 0 && surplusRankCredits == 0)
                    return;

                int payCredits = 0;
                int rankCredits = 0;
                if (surplusPayCredits > 0)
                    payCredits = surplusPayCredits < _creditconfiginfo.RegisterPayCredits ? surplusPayCredits : _creditconfiginfo.RegisterPayCredits;
                else if (surplusPayCredits == -1)
                    payCredits = _creditconfiginfo.RegisterPayCredits;
                if (surplusRankCredits > 0)
                    rankCredits = surplusRankCredits < _creditconfiginfo.RegisterRankCredits ? surplusRankCredits : _creditconfiginfo.RegisterRankCredits;
                else if (surplusRankCredits == -1)
                    rankCredits = _creditconfiginfo.RegisterRankCredits;

                userInfo.PayCredits += payCredits;
                userInfo.RankCredits += rankCredits;

                int userRid = UserRanks.GetUserRankByCredits(userInfo.RankCredits).UserRid;
                if (userRid != userInfo.UserRid)
                    userInfo.UserRid = userRid;
                else
                    userRid = 0;

                CreditLogInfo creditLogInfo = new CreditLogInfo();
                creditLogInfo.Uid = userInfo.Uid;
                creditLogInfo.PayCredits = payCredits;
                creditLogInfo.RankCredits = rankCredits;
                creditLogInfo.Action = (int)CreditAction.Register;
                creditLogInfo.ActionCode = 0;
                creditLogInfo.ActionTime = registerTime;
                creditLogInfo.ActionDes = "注册赠送积分";
                creditLogInfo.Operator = 0;

                SendCredits(userRid, creditLogInfo);
            }
        }
예제 #8
0
        /// <summary>
        /// 初始化用户
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="uNamePrefix">用户名前缀</param>
        /// <param name="regionId">区域id</param>
        /// <returns></returns>
        private static UserInfo InitUser(string userName, string uNamePrefix, int regionId)
        {
            UserInfo userInfo = new UserInfo();

            userInfo.Salt = Randoms.CreateRandomValue(6);
            userInfo.Password = Users.CreateUserPassword(Randoms.CreateRandomValue(32, false), userInfo.Salt);
            userInfo.AdminGid = 1;//非管理员组
            userInfo.UserName = GetValidUserName(userName, uNamePrefix);
            userInfo.Email = string.Empty;
            userInfo.Mobile = string.Empty;
            userInfo.NickName = StringHelper.SubString(userName, 20);
            userInfo.Avatar = "";
            userInfo.PayCredits = 0;
            userInfo.RankCredits = 0;
            userInfo.VerifyEmail = 0;
            userInfo.VerifyMobile = 0;
            userInfo.UserRid = UserRanks.GetUserRankByCredits(userInfo.PayCredits).UserRid;//根据积分判读用户等级
            userInfo.LiftBanTime = new DateTime(1900, 1, 1);
            userInfo.LastVisitTime = DateTime.Now;
            userInfo.LastVisitIP = WebHelper.GetIP();
            userInfo.LastVisitRgId = regionId;
            userInfo.RegisterTime = DateTime.Now;
            userInfo.RegisterIP = WebHelper.GetIP();
            userInfo.RegisterRgId = regionId;
            userInfo.Gender = 0;
            userInfo.RealName = string.Empty;
            userInfo.Bday = new DateTime(1900, 1, 1);
            userInfo.IdCard = string.Empty;
            userInfo.RegionId = 0;
            userInfo.Address = string.Empty;
            userInfo.Bio = string.Empty;

            return userInfo;
        }
예제 #9
0
        /// <summary>
        /// 注册
        /// </summary>
        public ActionResult Register()
        {
            string returnUrl = WebHelper.GetQueryString("returnUrl");
            if (returnUrl.Length == 0)
                returnUrl = "/";

            if (WorkContext.ShopConfig.RegType.Length == 0)
                return PromptView(returnUrl, "商城目前已经关闭注册功能!");
            if (WorkContext.Uid > 0)
                return PromptView(returnUrl, "你已经是本商城的注册用户,无需再注册!");
            if (WorkContext.ShopConfig.RegTimeSpan > 0)
            {
                var registerTime = Users.GetRegisterTimeByRegisterIP(WorkContext.IP);
                if ((DateTime.Now - registerTime).Minutes <= WorkContext.ShopConfig.RegTimeSpan)
                    return PromptView(returnUrl, "你注册太频繁,请间隔一定时间后再注册!");
            }

            //get请求
            if (WebHelper.IsGet())
            {
                var model = new RegisterModel
                {
                    ReturnUrl = returnUrl,
                    ShadowName = WorkContext.ShopConfig.ShadowName,
                    IsVerifyCode = CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.ShopConfig.VerifyPages)
                };

                return View(model);
            }

            //ajax请求
            var accountName = WebHelper.GetFormString(WorkContext.ShopConfig.ShadowName).Trim().ToLower();
            var password = WebHelper.GetFormString("password");
            var confirmPwd = WebHelper.GetFormString("confirmPwd");
            var verifyCode = WebHelper.GetFormString("verifyCode");

            var errorList = new StringBuilder("[");
            #region 验证

            //账号验证
            if (string.IsNullOrWhiteSpace(accountName))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名不能为空", "}");
            }
            else if (accountName.Length < 4 || accountName.Length > 50)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名必须大于3且不大于50个字符", "}");
            }
            else if (accountName.Contains(" "))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含空格", "}");
            }
            else if (accountName.Contains(":"))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含冒号", "}");
            }
            else if (accountName.Contains("<"))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含'<'符号", "}");
            }
            else if (accountName.Contains(">"))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含'>'符号", "}");
            }
            else if ((!SecureHelper.IsSafeSqlString(accountName)))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名已经存在", "}");
            }
            else if (CommonHelper.IsInArray(accountName, WorkContext.ShopConfig.ReservedName, "\n"))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名已经存在", "}");
            }
            else if (FilterWords.IsContainWords(accountName))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名包含禁止单词", "}");
            }

            //密码验证
            if (string.IsNullOrWhiteSpace(password))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码不能为空", "}");
            }
            else if (password.Length < 4 || password.Length > 32)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码必须大于3且不大于32个字符", "}");
            }
            else if (password != confirmPwd)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "两次输入的密码不一样", "}");
            }

            //验证码验证
            if (CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.ShopConfig.VerifyPages))
            {
                if (string.IsNullOrWhiteSpace(verifyCode))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "verifyCode", "验证码不能为空", "}");
                }
                else if (verifyCode.ToLower() != Sessions.GetValueString(WorkContext.Sid, "verifyCode"))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "verifyCode", "验证码不正确", "}");
                }
            }

            //其它验证
            var gender = WebHelper.GetFormInt("gender");
            if (gender < 0 || gender > 2)
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "gender", "请选择正确的性别", "}");

            var nickName = WebHelper.GetFormString("nickName");
            if (nickName.Length > 10)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "nickName", "昵称的长度不能大于10", "}");
            }
            else if (FilterWords.IsContainWords(nickName))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "nickName", "昵称中包含禁止单词", "}");
            }

            if (WebHelper.GetFormString("realName").Length > 5)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "realName", "真实姓名的长度不能大于5", "}");
            }

            var bday = WebHelper.GetFormString("bday");
            if (bday.Length == 0)
            {
                var bdayY = WebHelper.GetFormString("bdayY");
                var bdayM = WebHelper.GetFormString("bdayM");
                var bdayD = WebHelper.GetFormString("bdayD");
                bday = $"{bdayY}-{bdayM}-{bdayD}";
            }
            if (bday.Length > 0 && bday != "--" && !ValidateHelper.IsDate(bday))
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "bday", "请选择正确的日期", "}");

            string idCard = WebHelper.GetFormString("idCard");
            if (idCard.Length > 0 && !ValidateHelper.IsIdCard(idCard))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "idCard", "请输入正确的身份证号", "}");
            }

            var regionId = WebHelper.GetFormInt("regionId");
            if (regionId > 0)
            {
                if (Regions.GetRegionById(regionId) == null)
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "regionId", "请选择正确的地址", "}");
                if (WebHelper.GetFormString("address").Length > 75)
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "address", "详细地址的长度不能大于75", "}");
                }
            }

            if (WebHelper.GetFormString("bio").Length > 150)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "bio", "简介的长度不能大于150", "}");
            }

            //当以上验证都通过时
            UserInfo userInfo = null;
            if (errorList.Length == 1)
            {
                if (WorkContext.ShopConfig.RegType.Contains("2") && ValidateHelper.IsEmail(accountName))//验证邮箱
                {
                    var emailProvider = CommonHelper.GetEmailProvider(accountName);
                    if (WorkContext.ShopConfig.AllowEmailProvider.Length != 0 && (!CommonHelper.IsInArray(emailProvider, WorkContext.ShopConfig.AllowEmailProvider, "\n")))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用'" + emailProvider + "'类型的邮箱", "}");
                    }
                    else if (CommonHelper.IsInArray(emailProvider, WorkContext.ShopConfig.BanEmailProvider, "\n"))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用'" + emailProvider + "'类型的邮箱", "}");
                    }
                    else if (Users.IsExistEmail(accountName))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "邮箱已经存在", "}");
                    }
                    else
                    {
                        userInfo = new UserInfo();
                        userInfo.UserName = string.Empty;
                        userInfo.Email = accountName;
                        userInfo.Mobile = string.Empty;
                    }
                }
                else if (WorkContext.ShopConfig.RegType.Contains("3") && ValidateHelper.IsMobile(accountName))//验证手机
                {
                    if (Users.IsExistMobile(accountName))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "手机号已经存在", "}");
                    }
                    else
                    {
                        userInfo = new UserInfo
                        {
                            UserName = string.Empty,
                            Email = string.Empty,
                            Mobile = accountName
                        };
                    }
                }
                else if (WorkContext.ShopConfig.RegType.Contains("1"))//验证用户名
                {
                    if (BrnShop.Services.Users.IsExistUserName(accountName))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名已经存在", "}");
                    }
                    else
                    {
                        userInfo = new UserInfo
                        {
                            UserName = accountName,
                            Email = string.Empty,
                            Mobile = string.Empty
                        };
                    }
                }
            }

            #endregion

            if (errorList.Length > 1)//验证失败
            {
                return AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true);
            }
            else//验证成功
            {
                #region 绑定用户信息

                if (userInfo != null)
                {
                    userInfo.Salt = Randoms.CreateRandomValue(6);
                    userInfo.Password = Users.CreateUserPassword(password, userInfo.Salt);
                    userInfo.UserRid = UserRanks.GetLowestUserRank().UserRid;
                    userInfo.AdminGid = 1;//非管理员组
                    if (nickName.Length > 0)
                        userInfo.NickName = WebHelper.HtmlEncode(nickName);
                    else
                        userInfo.NickName = "bsp" + Randoms.CreateRandomValue(7);
                    userInfo.Avatar = "";
                    userInfo.PayCredits = 0;
                    userInfo.RankCredits = 0;
                    userInfo.VerifyEmail = 0;
                    userInfo.VerifyMobile = 0;

                    userInfo.LastVisitIP = WorkContext.IP;
                    userInfo.LastVisitRgId = WorkContext.RegionId;
                    userInfo.LastVisitTime = DateTime.Now;
                    userInfo.RegisterIP = WorkContext.IP;
                    userInfo.RegisterRgId = WorkContext.RegionId;
                    userInfo.RegisterTime = DateTime.Now;

                    userInfo.Gender = WebHelper.GetFormInt("gender");
                    userInfo.RealName = WebHelper.HtmlEncode(WebHelper.GetFormString("realName"));
                    userInfo.Bday = bday.Length > 0 ? TypeHelper.StringToDateTime(bday) : new DateTime(1900, 1, 1);
                    userInfo.IdCard = WebHelper.GetFormString("idCard");
                    userInfo.RegionId = WebHelper.GetFormInt("regionId");
                    userInfo.Address = WebHelper.HtmlEncode(WebHelper.GetFormString("address"));
                    userInfo.Bio = WebHelper.HtmlEncode(WebHelper.GetFormString("bio"));

                    #endregion

                    //创建用户
                    userInfo.Uid = Users.CreateUser(userInfo);

                    //添加用户失败
                    if (userInfo.Uid < 1)
                        return AjaxResult("exception", "创建用户失败,请联系管理员");

                    //发放注册积分
                    Credits.SendRegisterCredits(ref userInfo, DateTime.Now);
                    //更新购物车中用户id
                    Carts.UpdateCartUidBySid(userInfo.Uid, WorkContext.Sid);
                    //将用户信息写入cookie
                    ShopUtils.SetUserCookie(userInfo, 0);

                    //发送注册欢迎信息
                    if (WorkContext.ShopConfig.IsWebcomeMsg == 1)
                    {
                        if (userInfo.Email.Length > 0)
                            Emails.SendWebcomeEmail(userInfo.Email);
                        if (userInfo.Mobile.Length > 0)
                            SMSes.SendWebcomeSMS(userInfo.Mobile);
                    }

                    //同步上下午
                    WorkContext.Uid = userInfo.Uid;
                    WorkContext.UserName = userInfo.UserName;
                    WorkContext.UserEmail = userInfo.Email;
                    WorkContext.UserMobile = userInfo.Mobile;
                    WorkContext.NickName = userInfo.NickName;
                }

                return AjaxResult("success", "注册成功");
            }
        }