Пример #1
0
 public int UpdateUserRank(UserRanks Item)
 {
     try
     {
         SqlParameter[] parms = new SqlParameter[]
         {
             new SqlParameter("@Avatar", Item.Avatar),
             new SqlParameter("@CreditsLower", Item.CreditsLower),
             new SqlParameter("@CreditsUpper", Item.CreditsUpper),
             new SqlParameter("@LimitDays", Item.LimitDays),
             new SqlParameter("@System", Item.System),
             new SqlParameter("@Title", Item.Title),
             new SqlParameter("@UserRid", Item.UserRid),
         };
         StringBuilder sb = new StringBuilder();
         sb.Append(" UPDATE dbo.UserRanks ");
         sb.Append(" set Avatar=@Avatar ,CreditsLower=@CreditsLower,CreditsUpper=@CreditsUpper, ");
         sb.Append(" LimitDays=@LimitDays,System=@System,Title=@Title ");
         sb.Append(" where UserRid=@UserRid ");
         return(SQLHelper.ExcuteSQL(sb.ToString(), parms));
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Пример #2
0
 public EditUser(User user)
 {
     FirstName = user.FirstName;
     LastName  = user.LastName;
     Username  = user.Username;
     Rank      = user.Rank;
 }
Пример #3
0
        /// <summary>
        /// 用户等级编辑展示数据
        /// </summary>
        /// <param name="Rank"></param>
        /// <returns></returns>
        public IActionResult _EditUserRanks(int Rank)
        {
            if (Rank <= 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "找不到该等级!")));
            }
            UserRanks          userRanks = userRanksService.GetFullUserRanks(Rank);
            EditUserRanksModel model     = new EditUserRanksModel()
            {
                PointLower = userRanks.PointLower,
                RankName   = userRanks.RankName
            };

            return(View(model));
        }
Пример #4
0
        public IActionResult EditUserRanks(EditUserRanksModel model)
        {
            if (model.Rank <= 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "找不到该等级!")));
            }
            UserRanks userRanks = userRanksService.GetFullUserRanks(model.Rank);

            userRanks.RankName   = model.RankName;
            userRanks.PointLower = model.PointLower;

            bool result = userRanksService.EditUserRanks(userRanks);

            if (result)
            {
                return(Json(new StatusMessageData(StatusMessageType.Success, "编辑成功!")));
            }
            return(Json(new StatusMessageData(StatusMessageType.Error, "编辑失败!")));
        }
Пример #5
0
        public List <UserRanks> DataTableToList(DataTable dt)
        {
            List <UserRanks> ResList = new List <UserRanks>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var dr   = dt.Rows[i];
                var Item = new UserRanks()
                {
                    UserRid      = Convert.IsDBNull(dr["UserRid"]) ? 0 : Convert.ToInt32(dr["UserRid"]),
                    Avatar       = Convert.IsDBNull(dr["Avatar"]) ? "" : dr["Avatar"].ToString(),
                    CreditsLower = Convert.IsDBNull(dr["CreditsLower"]) ? 0 : Convert.ToInt32(dr["CreditsLower"]),
                    CreditsUpper = Convert.IsDBNull(dr["CreditsUpper"]) ? 0 : Convert.ToInt32(dr["CreditsUpper"]),
                    LimitDays    = Convert.IsDBNull(dr["LimitDays"]) ? 0 : Convert.ToInt32(dr["LimitDays"]),
                    System       = Convert.IsDBNull(dr["System"]) ? 0 : Convert.ToInt32(dr["System"]),
                    Title        = Convert.IsDBNull(dr["Title"]) ? "" : dr["Title"].ToString()
                };
                ResList.Add(Item);
            }
            return(ResList);
        }
Пример #6
0
 public int AddUserRank(UserRanks Item)
 {
     try
     {
         SqlParameter[] parms = new SqlParameter[]
         {
             new SqlParameter("@Avatar", Item.Avatar),
             new SqlParameter("@CreditsLower", Item.CreditsLower),
             new SqlParameter("@CreditsUpper", Item.CreditsUpper),
             new SqlParameter("@LimitDays", Item.LimitDays),
             new SqlParameter("@System", Item.System),
             new SqlParameter("@Title", Item.Title),
         };
         StringBuilder sb = new StringBuilder();
         sb.Append(" INSERT INTO dbo.UserRanks ");
         sb.Append(" (System,Title,Avatar,CreditsLower,CreditsUpper,LimitDays,System,Title) ");
         sb.Append(" Values(@System,@Title,@Avatar,@CreditsLower,@CreditsUpper,@LimitDays,@System,@Title) ");
         return(SQLHelper.ExcuteSQL(sb.ToString(), parms));
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Пример #7
0
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);

            WorkContext.IsHttpAjax  = WebHelper.IsAjax();
            WorkContext.IP          = WebHelper.GetIP();
            WorkContext.RegionInfo  = Regions.GetRegionByIP(WorkContext.IP);
            WorkContext.RegionId    = WorkContext.RegionInfo.RegionId;
            WorkContext.Url         = WebHelper.GetUrl();
            WorkContext.UrlReferrer = WebHelper.GetUrlReferrer();

            //获得用户唯一标示符sid
            WorkContext.Sid = ShopUtils.GetSidCookie();
            if (WorkContext.Sid.Length == 0)
            {
                //生成sid
                WorkContext.Sid = Sessions.GenerateSid();
                //将sid保存到cookie中
                ShopUtils.SetSidCookie(WorkContext.Sid);
            }

            PartUserInfo partUserInfo;

            //获得用户id
            int uid = ShopUtils.GetUidCookie();

            if (uid < 1)//当用户为游客时
            {
                //创建游客
                partUserInfo = Users.CreatePartGuest();
            }
            else//当用户为会员时
            {
                //获得保存在cookie中的密码
                string encryptPwd = ShopUtils.GetCookiePassword();
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    partUserInfo = Users.CreatePartGuest();
                    encryptPwd   = string.Empty;
                    ShopUtils.SetUidCookie(-1);
                    ShopUtils.SetCookiePassword("");
                }
                else
                {
                    partUserInfo = Users.GetPartUserByUidAndPwd(uid, ShopUtils.DecryptCookiePassword(encryptPwd));
                    if (partUserInfo != null)
                    {
                        //发放登陆积分
                        Credits.SendLoginCredits(ref partUserInfo, DateTime.Now);
                    }
                    else//当会员的账号或密码不正确时,将用户置为游客
                    {
                        partUserInfo = Users.CreatePartGuest();
                        encryptPwd   = string.Empty;
                        ShopUtils.SetUidCookie(-1);
                        ShopUtils.SetCookiePassword("");
                    }
                }
                WorkContext.EncryptPwd = encryptPwd;
            }

            //设置用户等级
            if (UserRanks.IsBanUserRank(partUserInfo.UserRid) && partUserInfo.LiftBanTime <= DateTime.Now)
            {
                UserRankInfo userRankInfo = UserRanks.GetUserRankByCredits(partUserInfo.PayCredits);
                Users.UpdateUserRankByUid(partUserInfo.Uid, userRankInfo.UserRid);
                partUserInfo.UserRid = userRankInfo.UserRid;
            }

            WorkContext.PartUserInfo = partUserInfo;

            WorkContext.Uid        = partUserInfo.Uid;
            WorkContext.UserName   = partUserInfo.UserName;
            WorkContext.UserEmail  = partUserInfo.Email;
            WorkContext.UserMobile = partUserInfo.Mobile;
            WorkContext.Password   = partUserInfo.Password;
            WorkContext.NickName   = partUserInfo.NickName;
            WorkContext.Avatar     = partUserInfo.Avatar;

            WorkContext.UserRid      = partUserInfo.UserRid;
            WorkContext.UserRankInfo = UserRanks.GetUserRankById(partUserInfo.UserRid);
            WorkContext.UserRTitle   = WorkContext.UserRankInfo.Title;
            //设置用户管理员组
            WorkContext.AdminGid       = partUserInfo.AdminGid;
            WorkContext.AdminGroupInfo = AdminGroups.GetAdminGroupById(partUserInfo.AdminGid);
            WorkContext.AdminGTitle    = WorkContext.AdminGroupInfo.Title;

            //设置当前控制器类名
            WorkContext.Controller = RouteData.Values["controller"].ToString().ToLower();
            //设置当前动作方法名
            WorkContext.Action  = RouteData.Values["action"].ToString().ToLower();
            WorkContext.PageKey = string.Format("/{0}/{1}", WorkContext.Controller, WorkContext.Action);
        }
Пример #8
0
        /// <summary>
        /// 登录
        /// </summary>
        public ActionResult Login()
        {
            string returnUrl = WebHelper.GetQueryString("returnUrl");

            if (returnUrl.Length == 0)
            {
                returnUrl = Url.Action("index", "home");
            }

            if (WorkContext.MallConfig.LoginType == "")
            {
                return(PromptView(returnUrl, "商城目前已经关闭登陆功能!"));
            }
            if (WorkContext.Uid > 0)
            {
                return(PromptView(returnUrl, "您已经登录,无须重复登录!"));
            }
            if (WorkContext.MallConfig.LoginFailTimes != 0 && LoginFailLogs.GetLoginFailTimesByIp(WorkContext.IP) >= WorkContext.MallConfig.LoginFailTimes)
            {
                return(PromptView(returnUrl, "您已经输入错误" + WorkContext.MallConfig.LoginFailTimes + "次密码,请15分钟后再登陆!"));
            }

            //get请求
            if (WebHelper.IsGet())
            {
                LoginModel model = new LoginModel();

                model.ReturnUrl       = returnUrl;
                model.ShadowName      = WorkContext.MallConfig.ShadowName;
                model.IsRemember      = WorkContext.MallConfig.IsRemember == 1;
                model.IsVerifyCode    = CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.MallConfig.VerifyPages);
                model.OAuthPluginList = Plugins.GetOAuthPluginList();

                return(View(model));
            }

            //ajax请求
            string accountName = WebHelper.GetFormString(WorkContext.MallConfig.ShadowName);
            string password    = WebHelper.GetFormString("password");
            string verifyCode  = WebHelper.GetFormString("verifyCode");
            int    isRemember  = WebHelper.GetFormInt("isRemember");

            StringBuilder errorList = new StringBuilder("[");

            //验证账户名
            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 ((!SecureHelper.IsSafeSqlString(accountName, false)))
            {
                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个字符", "}");
            }

            //验证验证码
            if (CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.MallConfig.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", "验证码不正确", "}");
                }
            }

            //当以上验证全部通过时
            PartUserInfo partUserInfo = null;

            if (errorList.Length == 1)
            {
                if (BMAConfig.MallConfig.LoginType.Contains("2") && ValidateHelper.IsEmail(accountName))//邮箱登陆
                {
                    partUserInfo = Users.GetPartUserByEmail(accountName);
                    if (partUserInfo == null)
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "邮箱不存在", "}");
                    }
                }
                else if (BMAConfig.MallConfig.LoginType.Contains("3") && ValidateHelper.IsMobile(accountName))//手机登陆
                {
                    partUserInfo = Users.GetPartUserByMobile(accountName);
                    if (partUserInfo == null)
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "手机不存在", "}");
                    }
                }
                else if (BMAConfig.MallConfig.LoginType.Contains("1"))//用户名登陆
                {
                    partUserInfo = Users.GetPartUserByName(accountName);
                    if (partUserInfo == null)
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名不存在", "}");
                    }
                }

                if (partUserInfo != null)
                {
                    if (Users.CreateUserPassword(password, partUserInfo.Salt) != partUserInfo.Password) //判断密码是否正确
                    {
                        LoginFailLogs.AddLoginFailTimes(WorkContext.IP, DateTime.Now);                  //增加登陆失败次数
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码不正确", "}");
                    }
                    else if (partUserInfo.UserRid == 1)              //当用户等级是禁止访问等级时
                    {
                        if (partUserInfo.LiftBanTime > DateTime.Now) //达到解禁时间
                        {
                            UserRankInfo userRankInfo = UserRanks.GetUserRankByCredits(partUserInfo.PayCredits);
                            Users.UpdateUserRankByUid(partUserInfo.Uid, userRankInfo.UserRid);
                            partUserInfo.UserRid = userRankInfo.UserRid;
                        }
                        else
                        {
                            errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "您的账号当前被锁定,不能访问", "}");
                        }
                    }
                }
            }

            if (errorList.Length > 1)//验证失败时
            {
                return(AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true));
            }
            else//验证成功时
            {
                //删除登陆失败日志
                LoginFailLogs.DeleteLoginFailLogByIP(WorkContext.IP);
                //更新用户最后访问
                Users.UpdateUserLastVisit(partUserInfo.Uid, DateTime.Now, WorkContext.IP, WorkContext.RegionId);
                //更新购物车中用户id
                Carts.UpdateCartUidBySid(partUserInfo.Uid, WorkContext.Sid);
                //将用户信息写入cookie中
                MallUtils.SetUserCookie(partUserInfo, (WorkContext.MallConfig.IsRemember == 1 && isRemember == 1) ? 30 : -1);

                return(AjaxResult("success", "登录成功"));
            }
        }
Пример #9
0
        /// <summary>
        /// 注册
        /// </summary>
        public ActionResult Register()
        {
            string returnUrl = WebHelper.GetQueryString("returnUrl");

            if (returnUrl.Length == 0)
            {
                returnUrl = Url.Action("index", "home");
            }

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

            //get请求
            if (WebHelper.IsGet())
            {
                RegisterModel model = new RegisterModel();

                model.ReturnUrl    = returnUrl;
                model.ShadowName   = WorkContext.MallConfig.ShadowName;
                model.IsVerifyCode = CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.MallConfig.VerifyPages);

                return(View(model));
            }

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

            StringBuilder 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, false)))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名不符合系统要求", "}");
            }
            else if (CommonHelper.IsInArray(accountName, WorkContext.MallConfig.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.MallConfig.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", "验证码不正确", "}");
                }
            }

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

            string 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", "}");
            }

            string bday = WebHelper.GetFormString("bday");
            if (bday.Length == 0)
            {
                string bdayY = WebHelper.GetFormString("bdayY");
                string bdayM = WebHelper.GetFormString("bdayM");
                string bdayD = WebHelper.GetFormString("bdayD");
                bday = string.Format("{0}-{1}-{2}", 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", "请输入正确的身份证号", "}");
            }

            int 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.MallConfig.RegType.Contains("2") && ValidateHelper.IsEmail(accountName))//验证邮箱
                {
                    string emailProvider = CommonHelper.GetEmailProvider(accountName);
                    if (WorkContext.MallConfig.AllowEmailProvider.Length != 0 && (!CommonHelper.IsInArray(emailProvider, WorkContext.MallConfig.AllowEmailProvider, "\n")))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用'" + emailProvider + "'类型的邮箱", "}");
                    }
                    else if (CommonHelper.IsInArray(emailProvider, WorkContext.MallConfig.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.MallConfig.RegType.Contains("3") && ValidateHelper.IsMobile(accountName))//验证手机
                {
                    if (Users.IsExistMobile(accountName))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "手机号已经存在", "}");
                    }
                    else
                    {
                        userInfo          = new UserInfo();
                        userInfo.UserName = string.Empty;
                        userInfo.Email    = string.Empty;
                        userInfo.Mobile   = accountName;
                    }
                }
                else if (WorkContext.MallConfig.RegType.Contains("1"))//验证用户名
                {
                    if (accountName.Length > 20)
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名长度不能超过20个字符", "}");
                    }
                    else if (BrnMall.Services.Users.IsExistUserName(accountName))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名已经存在", "}");
                    }
                    else
                    {
                        userInfo          = new UserInfo();
                        userInfo.UserName = accountName;
                        userInfo.Email    = string.Empty;
                        userInfo.Mobile   = string.Empty;
                    }
                }
            }

            #endregion

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

                userInfo.Salt     = Randoms.CreateRandomValue(6);
                userInfo.Password = Users.CreateUserPassword(password, userInfo.Salt);
                userInfo.UserRid  = UserRanks.GetLowestUserRank().UserRid;
                userInfo.StoreId  = 0;
                userInfo.MallAGid = 1;//非管理员组
                if (nickName.Length > 0)
                {
                    userInfo.NickName = WebHelper.HtmlEncode(nickName);
                }
                else
                {
                    userInfo.NickName = "bma" + 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
                MallUtils.SetUserCookie(userInfo, 0);

                //发送注册欢迎信息
                if (WorkContext.MallConfig.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", "注册成功"));
            }
        }
 public UserInfoStat()
 {
     Ranks = new UserRanks();
 }
Пример #11
0
        public ActionResult Add(UserModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Password))
            {
                ModelState.AddModelError("Password", "密码不能为空");
            }

            if (AdminUsers.IsExistUserName(model.UserName))
            {
                ModelState.AddModelError("UserName", "名称已经存在");
            }

            if (AdminUsers.IsExistEmail(model.Email))
            {
                ModelState.AddModelError("Email", "email已经存在");
            }

            if (AdminUsers.IsExistMobile(model.Mobile))
            {
                ModelState.AddModelError("Mobile", "手机号已经存在");
            }

            if (ModelState.IsValid)
            {
                string salt = Users.GenerateUserSalt();
                string nickName;
                if (string.IsNullOrWhiteSpace(model.NickName))
                {
                    nickName = "bsp" + Randoms.CreateRandomValue(7);
                }
                else
                {
                    nickName = model.NickName;
                }

                UserInfo userInfo = new UserInfo()
                {
                    UserName      = model.UserName,
                    Email         = model.Email == null ? "" : model.Email,
                    Mobile        = model.Mobile == null ? "" : model.Mobile,
                    Salt          = salt,
                    Password      = Users.CreateUserPassword(model.Password, salt),
                    UserRid       = model.UserRid,
                    AdminGid      = model.AdminGid,
                    NickName      = WebHelper.HtmlEncode(nickName),
                    Avatar        = model.Avatar == null ? "" : WebHelper.HtmlEncode(model.Avatar),
                    PayCredits    = model.PayCredits,
                    RankCredits   = AdminUserRanks.GetUserRankById(model.UserRid).CreditsLower,
                    VerifyEmail   = 1,
                    VerifyMobile  = 1,
                    LiftBanTime   = UserRanks.IsBanUserRank(model.UserRid) ? DateTime.Now.AddDays(WorkContext.UserRankInfo.LimitDays) : new DateTime(1900, 1, 1),
                    LastVisitTime = DateTime.Now,
                    LastVisitIP   = WorkContext.IP,
                    LastVisitRgId = WorkContext.RegionId,
                    RegisterTime  = DateTime.Now,
                    RegisterIP    = WorkContext.IP,
                    RegisterRgId  = WorkContext.RegionId,
                    Gender        = model.Gender,
                    RealName      = model.RealName == null ? "" : WebHelper.HtmlEncode(model.RealName),
                    Bday          = model.Bday ?? new DateTime(1970, 1, 1),
                    IdCard        = model.IdCard == null ? "" : model.IdCard,
                    RegionId      = model.RegionId,
                    Address       = model.Address == null ? "" : WebHelper.HtmlEncode(model.Address),
                    Bio           = model.Bio == null ? "" : WebHelper.HtmlEncode(model.Bio)
                };

                AdminUsers.CreateUser(userInfo);
                AddAdminOperateLog("添加用户", "添加用户,用户为:" + model.UserName);
                return(PromptView("用户添加成功"));
            }
            Load(model.RegionId);

            return(View(model));
        }
Пример #12
0
        public ActionResult Edit(UserModel model, int uid = -1)
        {
            UserInfo userInfo = AdminUsers.GetUserById(uid);

            if (userInfo == null)
            {
                return(PromptView("用户不存在"));
            }

            int uid2 = AdminUsers.GetUidByUserName(model.UserName);

            if (uid2 > 0 && uid2 != uid)
            {
                ModelState.AddModelError("UserName", "用户名已经存在");
            }

            int uid3 = AdminUsers.GetUidByEmail(model.Email);

            if (uid3 > 0 && uid3 != uid)
            {
                ModelState.AddModelError("Email", "邮箱已经存在");
            }

            int uid4 = AdminUsers.GetUidByMobile(model.Mobile);

            if (uid4 > 0 && uid4 != uid)
            {
                ModelState.AddModelError("Mobile", "手机号已经存在");
            }

            if (ModelState.IsValid)
            {
                string nickName;
                if (string.IsNullOrWhiteSpace(model.NickName))
                {
                    nickName = userInfo.NickName;
                }
                else
                {
                    nickName = model.NickName;
                }

                userInfo.UserName = model.UserName;
                userInfo.Email    = model.Email == null ? "" : model.Email;
                userInfo.Mobile   = model.Mobile == null ? "" : model.Mobile;
                if (!string.IsNullOrWhiteSpace(model.Password))
                {
                    userInfo.Password = Users.CreateUserPassword(model.Password, userInfo.Salt);
                }
                userInfo.UserRid     = model.UserRid;
                userInfo.AdminGid    = model.AdminGid;
                userInfo.NickName    = WebHelper.HtmlEncode(nickName);
                userInfo.Avatar      = model.Avatar == null ? "" : WebHelper.HtmlEncode(model.Avatar);
                userInfo.PayCredits  = model.PayCredits;
                userInfo.RankCredits = userInfo.UserRid == model.UserRid ? userInfo.RankCredits : AdminUserRanks.GetUserRankById(model.UserRid).CreditsLower;
                userInfo.LiftBanTime = UserRanks.IsBanUserRank(model.UserRid) ? DateTime.Now.AddDays(WorkContext.UserRankInfo.LimitDays) : new DateTime(1900, 1, 1);
                userInfo.Gender      = model.Gender;
                userInfo.RealName    = model.RealName == null ? "" : WebHelper.HtmlEncode(model.RealName);
                userInfo.Bday        = model.Bday ?? new DateTime(1970, 1, 1);
                userInfo.IdCard      = model.IdCard == null ? "" : model.IdCard;
                userInfo.RegionId    = model.RegionId;
                userInfo.Address     = model.Address == null ? "" : WebHelper.HtmlEncode(model.Address);
                userInfo.Bio         = model.Bio == null ? "" : WebHelper.HtmlEncode(model.Bio);

                AdminUsers.UpdateUser(userInfo);
                AddAdminOperateLog("修改用户", "修改用户,用户ID为:" + uid);
                return(PromptView("用户修改成功"));
            }

            Load(model.RegionId);

            return(View(model));
        }
Пример #13
0
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            this.ValidateRequest = false;

            WorkContext.IsHttpAjax  = WebHelper.IsAjax();
            WorkContext.IP          = WebHelper.GetIP();
            WorkContext.RegionInfo  = Regions.GetRegionByIP(WorkContext.IP);
            WorkContext.RegionId    = WorkContext.RegionInfo.RegionId;
            WorkContext.Url         = WebHelper.GetUrl();
            WorkContext.UrlReferrer = WebHelper.GetUrlReferrer();

            //获得用户唯一标示符sid
            WorkContext.Sid = MallUtils.GetSidCookie();
            if (WorkContext.Sid.Length == 0)
            {
                //生成sid
                WorkContext.Sid = Sessions.GenerateSid();
                //将sid保存到cookie中
                MallUtils.SetSidCookie(WorkContext.Sid);
            }

            PartUserInfo partUserInfo;

            //获得用户id
            int uid = MallUtils.GetUidCookie();

            if (uid < 1)//当用户为游客时
            {
                //创建游客
                partUserInfo = Users.CreatePartGuest();
            }
            else//当用户为会员时
            {
                //获得保存在cookie中的密码
                string encryptPwd = MallUtils.GetCookiePassword();
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    partUserInfo = Users.CreatePartGuest();
                    encryptPwd   = string.Empty;
                    MallUtils.SetUidCookie(-1);
                    MallUtils.SetCookiePassword("");
                }
                else
                {
                    partUserInfo = Users.GetPartUserByUidAndPwd(uid, MallUtils.DecryptCookiePassword(encryptPwd));
                    if (partUserInfo != null)
                    {
                        //发放登陆积分
                        Credits.SendLoginCredits(ref partUserInfo, DateTime.Now);
                    }
                    else//当会员的账号或密码不正确时,将用户置为游客
                    {
                        partUserInfo = Users.CreatePartGuest();
                        encryptPwd   = string.Empty;
                        MallUtils.SetUidCookie(-1);
                        MallUtils.SetCookiePassword("");
                    }
                }
                WorkContext.EncryptPwd = encryptPwd;
            }

            //设置用户等级
            if (UserRanks.IsBanUserRank(partUserInfo.UserRid) && partUserInfo.LiftBanTime <= DateTime.Now)
            {
                UserRankInfo userRankInfo = UserRanks.GetUserRankByCredits(partUserInfo.PayCredits);
                Users.UpdateUserRankByUid(partUserInfo.Uid, userRankInfo.UserRid);
                partUserInfo.UserRid = userRankInfo.UserRid;
            }

            //当用户被禁止访问时重置用户为游客
            if (partUserInfo.UserRid == 1)
            {
                partUserInfo           = Users.CreatePartGuest();
                WorkContext.EncryptPwd = string.Empty;
                MallUtils.SetUidCookie(-1);
                MallUtils.SetCookiePassword("");
            }

            WorkContext.PartUserInfo = partUserInfo;

            WorkContext.Uid             = partUserInfo.Uid;
            WorkContext.UserName        = partUserInfo.UserName;
            WorkContext.UserEmail       = partUserInfo.Email;
            WorkContext.UserMobile      = partUserInfo.Mobile;
            WorkContext.Password        = partUserInfo.Password;
            WorkContext.NickName        = partUserInfo.NickName;
            WorkContext.Avatar          = partUserInfo.Avatar;
            WorkContext.PayCreditName   = Credits.PayCreditName;
            WorkContext.PayCreditCount  = partUserInfo.PayCredits;
            WorkContext.RankCreditName  = Credits.RankCreditName;
            WorkContext.RankCreditCount = partUserInfo.RankCredits;

            WorkContext.UserRid      = partUserInfo.UserRid;
            WorkContext.UserRankInfo = UserRanks.GetUserRankById(partUserInfo.UserRid);
            WorkContext.UserRTitle   = WorkContext.UserRankInfo.Title;
            //设置用户商城管理员组
            WorkContext.MallAGid           = partUserInfo.MallAGid;
            WorkContext.MallAdminGroupInfo = MallAdminGroups.GetMallAdminGroupById(partUserInfo.MallAGid);
            WorkContext.MallAGTitle        = WorkContext.MallAdminGroupInfo.Title;

            //设置当前控制器类名
            WorkContext.Controller = RouteData.Values["controller"].ToString().ToLower();
            //设置当前动作方法名
            WorkContext.Action  = RouteData.Values["action"].ToString().ToLower();
            WorkContext.PageKey = string.Format("/{0}/{1}", WorkContext.Controller, WorkContext.Action);

            WorkContext.ImageCDN  = WorkContext.MallConfig.ImageCDN;
            WorkContext.CSSCDN    = WorkContext.MallConfig.CSSCDN;
            WorkContext.ScriptCDN = WorkContext.MallConfig.ScriptCDN;

            //在线总人数
            WorkContext.OnlineUserCount = OnlineUsers.GetOnlineUserCount();
            //在线游客数
            WorkContext.OnlineGuestCount = OnlineUsers.GetOnlineGuestCount();
            //在线会员数
            WorkContext.OnlineMemberCount = WorkContext.OnlineUserCount - WorkContext.OnlineGuestCount;
            //搜索词
            WorkContext.SearchWord = string.Empty;
            //购物车中商品数量
            WorkContext.CartProductCount = Carts.GetCartProductCountCookie();

            //设置导航列表
            WorkContext.NavList = Navs.GetNavList();
            //设置友情链接列表
            WorkContext.FriendLinkList = FriendLinks.GetFriendLinkList();
            //设置帮助列表
            WorkContext.HelpList = Helps.GetHelpList();
        }
Пример #14
0
 public int AddUserRank(UserRanks Item)
 {
     return(_dal.AddUserRank(Item));
 }
Пример #15
0
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            this.ValidateRequest = false;

            WorkContext.IsHttpAjax  = WebHelper.IsAjax();
            WorkContext.IP          = WebHelper.GetIP();
            WorkContext.RegionInfo  = Regions.GetRegionByIP(WorkContext.IP);
            WorkContext.RegionId    = WorkContext.RegionInfo.RegionId;
            WorkContext.Url         = WebHelper.GetUrl();
            WorkContext.UrlReferrer = WebHelper.GetUrlReferrer();

            //获得用户唯一标示符sid
            WorkContext.Sid    = MallUtils.GetSidCookie();
            WorkContext.Openid = "";
            if (WorkContext.Sid.Length == 0)
            {
                //生成sid
                WorkContext.Sid = Sessions.GenerateSid();
                //将sid保存到cookie中
                MallUtils.SetSidCookie(WorkContext.Sid);
            }

            PartUserInfo partUserInfo;

            //获得用户id
            int uid = MallUtils.GetUidCookie();

            if (uid < 1)//当用户为游客时
            {
                //创建游客
                partUserInfo = Users.CreatePartGuest();
                BrnMall.Core.WeiXinConfig wxconfig = BrnMall.Core.BMAConfig.WeiXinConfig;
                #region 获取用户openid
                //if (Request.QueryString["code"] == null)
                //{
                //    string host = Request.Url.Host;
                //    string path = Request.Path;
                //    string url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", wxconfig.AppID, System.Web.HttpUtility.UrlEncode("http://" + host + path));

                //    Response.Redirect(url);
                //}
                //else
                //{

                //    //BrnMall.Core.WeiXinConfig wxconfig = BrnMall.Core.BMAConfig.WeiXinConfig;
                //    string code = Request.QueryString["code"];//获取授权code
                //                                              // string openIdUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxconfig.AppID + "&secret=" + wxconfig.AppSecret + "&code=" + code + "&grant_type=authorization_code";
                //    string openIdUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxconfig.AppID + "&secret=" + wxconfig.AppSecret + "&code=" + code + "&grant_type=authorization_code";
                //    string content = "";
                //    try
                //    {
                //        content = BrnMall.Core.WeiXinHelp.GetPage(openIdUrl, "");

                //    }
                //    catch
                //    {
                //        Response.Write("code:" + code + "这边错了");
                //    }

                //    string openid = "";//根据授权  获取当前人的openid
                //    try
                //    {
                //        openid = BrnMall.Core.WeiXinHelp.GetJsonValue(content, "openid");

                //    }
                //    catch
                //    {
                //        Response.Write("code:" + code + "||||content" + content);
                //    }
                //    Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson dic = null;

                //    dic = Senparc.Weixin.MP.AdvancedAPIs.UserApi.Info(WeiXinHelp.IsExistAccess_Token2(), openid);

                //    if (dic.subscribe == 1)
                //    {
                //        //获取用户
                //        //try
                //        //{
                //        //BMALog.Instance.Write("openid:" + openid);
                //        partUserInfo = Users.GetPartUserByOpenid(openid);

                //        if (partUserInfo != null)
                //        {


                //            MallUtils.SetUserCookie(partUserInfo, 30);
                //            //WorkContext.EncryptPwd= MallUtils.GetCookiePassword();
                //        }
                //        else//不存在
                //        {
                //            //partUserInfo = Users.CreatePartGuest();
                //            //WorkContext.EncryptPwd = string.Empty;
                //            //MallUtils.SetUidCookie(-1);
                //            //MallUtils.SetCookiePassword("");
                //            UserInfo userinfo = new UserInfo();

                //            userinfo.Pid = 3;
                //            userinfo.Openid = dic.openid;
                //            userinfo.NickName = dic.nickname;
                //            userinfo.UserName = dic.nickname;
                //            userinfo.Password = Users.CreateUserPassword("Migewan123", "1");
                //            userinfo.Avatar = dic.headimgurl;
                //            userinfo.UserLevel = 0;
                //            userinfo.PayCredits = 0;
                //            userinfo.RankCredits = 0;
                //            userinfo.VerifyEmail = 0;
                //            userinfo.VerifyMobile = 0;
                //            userinfo.Salt = Randoms.CreateRandomValue(6);
                //            userinfo.LastVisitIP = WebHelper.GetIP();
                //            userinfo.MallAGid = 1;//非管理员组
                //                                  //userinfo.LastVisitRgId = Regions.GetRegionByIP(userinfo.LastVisitIP);
                //            userinfo.LastVisitTime = DateTime.Now;
                //            userinfo.RegisterIP = WebHelper.GetIP();

                //            userinfo.RegisterTime = DateTime.Now;
                //            Users.CreateUser(userinfo);
                //            partUserInfo = Users.GetPartUserByOpenid(openid);
                //            MallUtils.SetUserCookie(partUserInfo, 30);
                //        }
                //    }
                //}


                #endregion
                #region 测试
                ////string openid = "oD-R9wWHGhJ3rcRgX7sbU5W0s9sU";
                string openid = "oD-R9wbVoaX-B-7kmk7sz1nz_-bc";
                partUserInfo = Users.GetPartUserByOpenid(openid);
                if (partUserInfo != null)
                {
                    MallUtils.SetUserCookie(partUserInfo, 30);
                    //WorkContext.EncryptPwd= MallUtils.GetCookiePassword();
                }
                else//不存在
                {
                    partUserInfo           = Users.CreatePartGuest();
                    WorkContext.EncryptPwd = string.Empty;
                    MallUtils.SetUidCookie(-1);
                    MallUtils.SetCookiePassword("");
                }
                #endregion
            }
            else//当用户为会员时
            {
                //获得保存在cookie中的密码
                string encryptPwd = MallUtils.GetCookiePassword();
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    partUserInfo = Users.CreatePartGuest();
                    encryptPwd   = string.Empty;
                    MallUtils.SetUidCookie(-1);
                    MallUtils.SetCookiePassword("");
                }
                else
                {
                    partUserInfo = Users.GetPartUserByUidAndPwd(uid, MallUtils.DecryptCookiePassword(encryptPwd));
                    if (partUserInfo != null)
                    {
                        //发放登陆积分
                        // Credits.SendLoginCredits(ref partUserInfo, DateTime.Now);
                    }
                    else//当会员的账号或密码不正确时,将用户置为游客
                    {
                        partUserInfo = Users.CreatePartGuest();
                        encryptPwd   = string.Empty;
                        MallUtils.SetUidCookie(-1);
                        MallUtils.SetCookiePassword("");
                    }
                }
                WorkContext.EncryptPwd = encryptPwd;
            }
            //try
            //{
            //设置用户等级
            if (UserRanks.IsBanUserRank(partUserInfo.UserRid) && partUserInfo.LiftBanTime <= DateTime.Now)
            {
                UserRankInfo userRankInfo = UserRanks.GetUserRankByCredits(partUserInfo.PayCredits);
                Users.UpdateUserRankByUid(partUserInfo.Uid, userRankInfo.UserRid);
                partUserInfo.UserRid = userRankInfo.UserRid;
            }

            //当用户被禁止访问时重置用户为游客
            if (partUserInfo.UserRid == 1)
            {
                partUserInfo           = Users.CreatePartGuest();
                WorkContext.EncryptPwd = string.Empty;
                MallUtils.SetUidCookie(-1);
                MallUtils.SetCookiePassword("");
            }
            //}
            //catch
            //{
            //    Response.Write("我的错");
            //}
            //try
            //{
            WorkContext.PartUserInfo = partUserInfo;
            WorkContext.Pid          = partUserInfo.Pid;
            WorkContext.Userno       = partUserInfo.Userno;
            WorkContext.UserLevel    = partUserInfo.UserLevel;
            WorkContext.Openid       = partUserInfo.Openid;
            WorkContext.Addtime      = partUserInfo.Addtime;
            WorkContext.IsReal       = partUserInfo.IsReal;


            WorkContext.Uid             = partUserInfo.Uid;
            WorkContext.UserName        = partUserInfo.UserName;
            WorkContext.UserEmail       = partUserInfo.Email;
            WorkContext.UserMobile      = partUserInfo.Mobile;
            WorkContext.Password        = partUserInfo.Password;
            WorkContext.NickName        = partUserInfo.NickName;
            WorkContext.Avatar          = partUserInfo.Avatar;
            WorkContext.PayCreditName   = Credits.PayCreditName;
            WorkContext.PayCreditCount  = partUserInfo.PayCredits;
            WorkContext.RankCreditName  = Credits.RankCreditName;
            WorkContext.RankCreditCount = partUserInfo.RankCredits;
            Core.BLL.SendBag bllsendbag = new Core.BLL.SendBag();
            //全部红包
            //WorkContext.CollarBag = bllsendbag.GetRecordSum(" Receiverid="+ partUserInfo.Uid );


            //已领红包
            WorkContext.NoCollarBag = bllsendbag.GetRecordSum(" Receiverid=" + partUserInfo.Uid + " and Status=0");;
            //未领红包
            WorkContext.HaCollarBag  = 0;
            WorkContext.UserRid      = partUserInfo.UserRid;
            WorkContext.UserRankInfo = UserRanks.GetUserRankById(partUserInfo.UserRid);
            //WorkContext.UserRTitle = WorkContext.UserRankInfo.Title;
            switch (WorkContext.UserLevel)
            {
            case 1:
                WorkContext.UserRTitle = "银卡会员";
                break;

            case 2:
                WorkContext.UserRTitle = "金卡会员";
                break;

            case 3:
                WorkContext.UserRTitle = "钻石会员";
                break;

            default:
                WorkContext.UserRTitle = "普通会员";
                break;
            }
            //设置用户商城管理员组
            WorkContext.MallAGid           = partUserInfo.MallAGid;
            WorkContext.MallAdminGroupInfo = MallAdminGroups.GetMallAdminGroupById(partUserInfo.MallAGid);
            WorkContext.MallAGTitle        = WorkContext.MallAdminGroupInfo.Title;

            //设置当前控制器类名
            WorkContext.Controller = RouteData.Values["controller"].ToString().ToLower();
            //设置当前动作方法名
            WorkContext.Action  = RouteData.Values["action"].ToString().ToLower();
            WorkContext.PageKey = string.Format("/{0}/{1}", WorkContext.Controller, WorkContext.Action);

            WorkContext.ImageCDN  = WorkContext.MallConfig.ImageCDN;
            WorkContext.CSSCDN    = WorkContext.MallConfig.CSSCDN;
            WorkContext.ScriptCDN = WorkContext.MallConfig.ScriptCDN;

            //在线总人数
            WorkContext.OnlineUserCount = OnlineUsers.GetOnlineUserCount();
            //在线游客数
            WorkContext.OnlineGuestCount = OnlineUsers.GetOnlineGuestCount();
            //在线会员数
            WorkContext.OnlineMemberCount = WorkContext.OnlineUserCount - WorkContext.OnlineGuestCount;
            //搜索词
            WorkContext.SearchWord = string.Empty;
            //购物车中商品数量
            WorkContext.CartProductCount = Carts.GetCartProductCountCookie();
            //}
            //catch (Exception ex)
            //{
            //    Response.Write("赋值时:"+ex.ToString());
            //}
        }
Пример #16
0
        /// <summary>
        /// 订阅宝SSO登录
        /// </summary>
        public ActionResult DybLogin()
        {
            try
            {
                LogUtil.WriteLog($"开始登陆 url:{WebHelper.GetRawUrl()}");
                if (WorkContext.Uid > 0)
                {
                    WebHelper.DeleteCookie("bma");
                    Sessions.RemoverSession(WorkContext.Sid);
                    OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid);
                }
                string username    = WebHelper.GetQueryString("username");
                string agentname   = WebHelper.GetQueryString("agentname");
                string redirectUrl = WebHelper.GetQueryString("redirect");
                string ak          = WebHelper.GetQueryString("ak");
                if (string.IsNullOrEmpty(username))
                {
                    return(PromptView("该单点登录链接缺少用户信息"));
                }

                var storepid = 0;
                if (!string.IsNullOrEmpty(agentname))
                {
                    var agentUid = OAuths.GetUidByOpenIdAndServer(agentname, "dyb");
                    if (agentUid > 0)
                    {
                        var agentUser = Users.GetPartUserById(agentUid);
                        storepid = agentUser.StoreId;
                    }
                }
                var uid = OAuths.GetUidByOpenIdAndServer(username, "dyb");
                if (uid < 1)
                {
                    //创建用户
                    var userInfo = OAuths.CreateOAuthUser(DateTime.Now.ToString("yyMMddHHmmssms"), "dyb", username, "dyb",
                                                          WorkContext.RegionId);
                    uid = userInfo.Uid;
                }
                var partUserInfo = Users.GetPartUserById(uid);
                if (partUserInfo.StoreId == 0)
                {
                    //创建店铺
                    var storeId = AdminStores.CreateStore(new StoreInfo
                    {
                        Announcement = "",
                        Banner       = "",
                        CreateTime   = DateTime.Now,
                        DePoint      = 10,
                        Description  = "",
                        Honesties    = 0,
                        Logo         = "",
                        Mobile       = "",
                        Name         = "微信小程序",
                        Phone        = "",
                        QQ           = "",
                        RegionId     = 0,
                        SePoint      = 10,
                        ShPoint      = 10,
                        State        = 0,
                        StateEndTime = DateTime.Now.AddYears(1),
                        StoreIid     = 0,
                        StoreRid     = 1,
                        Theme        = "default",
                        WW           = "",
                        StorePid     = storepid
                    }, new StoreKeeperInfo
                    {
                        Address = username,
                        IdCard  = username,
                        Name    = partUserInfo.UserName,
                        Type    = 0
                    });

                    AdminStores.CreateStoreShipTemplate(new StoreShipTemplateInfo
                    {
                        Free    = 1,
                        StoreId = storeId,
                        Title   = "全场包邮",
                        Type    = 0
                    });

                    //创建会员等级
                    AdminUserRanks.CreateUserRank(new UserRankInfo
                    {
                        Avatar       = string.Empty,
                        CreditsLower = 0,
                        CreditsUpper = -1,
                        LimitDays    = 0,
                        StoreId      = storeId,
                        System       = 0,
                        Title        = "初级会员"
                    });
                    partUserInfo.StoreId = storeId;
                    partUserInfo.UserRid = UserRanks.GetLowestUserRank(storeId).UserRid;
                    WorkContext.StoreId  = storeId;

                    Users.UpdatePartUser(partUserInfo);
                }
                //如果对应的店铺没有平台ID,则可以更改storepid,否则不行
                if (storepid > 0)
                {
                    var store = Stores.GetStoreById(partUserInfo.StoreId);
                    if (store != null && store.StorePid == 0 && store.StoreId != storepid)
                    {
                        AdminStores.UpdateStorePId(store.StoreId, storepid);
                    }
                }

                //将用户信息写入cookie中
                MallUtils.SetUserCookie(partUserInfo, 365);
                StoreInfoManager.UpdateDistributor(partUserInfo.StoreId,
                                                   ak.Equals("dis", StringComparison.InvariantCultureIgnoreCase));
                LogUtil.WriteLog($"开始登陆 开始跳转");
                if (string.IsNullOrEmpty(redirectUrl))
                {
                    return(RedirectToAction("index", "home", new RouteValueDictionary {
                        { "area", "storeadmin" }
                    }));
                }
                else
                {
                    return(Redirect(redirectUrl));
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                throw;
            }
        }
Пример #17
0
        /// <summary>
        /// 接口方式访问没有记录cookie,通过用户账号来获取信息
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        private PartUserInfo InitUser(string account)
        {
            partUserInfo = Users.GetPartUserByMobile(account);
            if (partUserInfo.Uid == 0)
            {
                //创建游客
                partUserInfo = Users.CreatePartGuest();
            }
            //获得用户id
            int uid = partUserInfo.Uid;


            //设置用户等级
            if (UserRanks.IsBanUserRank(partUserInfo.UserRid) && partUserInfo.LiftBanTime <= DateTime.Now)
            {
                UserRankInfo userRankInfo = UserRanks.GetUserRankByCredits(partUserInfo.PayCredits);
                Users.UpdateUserRankByUid(partUserInfo.Uid, userRankInfo.UserRid);
                partUserInfo.UserRid = userRankInfo.UserRid;
            }

            //当用户被禁止访问时重置用户为游客
            if (partUserInfo.UserRid == 1)
            {
                partUserInfo           = Users.CreatePartGuest();
                WorkContext.EncryptPwd = string.Empty;
                ShopUtils.SetUidCookie(-1, "web");
                ShopUtils.SetCookiePassword("", "web");
            }

            WorkContext.PartUserInfo = partUserInfo;

            WorkContext.Uid        = partUserInfo.Uid;
            WorkContext.UserName   = partUserInfo.UserName;
            WorkContext.UserEmail  = partUserInfo.Email;
            WorkContext.UserMobile = partUserInfo.Mobile;
            WorkContext.Password   = partUserInfo.Password;
            WorkContext.NickName   = partUserInfo.NickName;
            WorkContext.Avatar     = partUserInfo.Avatar;

            WorkContext.UserRid      = partUserInfo.UserRid;
            WorkContext.UserRankInfo = UserRanks.GetUserRankById(partUserInfo.UserRid);
            WorkContext.UserRTitle   = WorkContext.UserRankInfo.Title;
            //设置用户管理员组
            WorkContext.AdminGid       = partUserInfo.AdminGid;
            WorkContext.AdminGroupInfo = AdminGroups.GetAdminGroupById(partUserInfo.AdminGid);
            WorkContext.AdminGTitle    = WorkContext.AdminGroupInfo.Title;

            //设置当前控制器类名
            WorkContext.Controller = RouteData.Values["controller"].ToString().ToLower();
            //设置当前动作方法名
            WorkContext.Action  = RouteData.Values["action"].ToString().ToLower();
            WorkContext.PageKey = string.Format("/{0}/{1}", WorkContext.Controller, WorkContext.Action);

            //当前商城主题
            WorkContext.Theme = WorkContext.ShopConfig.PCTheme;
            //设置图片cdn
            WorkContext.ImageCDN = WorkContext.ShopConfig.ImageCDN;
            //设置csscdn
            WorkContext.CSSCDN = WorkContext.ShopConfig.CSSCDN;
            //设置脚本cdn
            WorkContext.ScriptCDN = WorkContext.ShopConfig.ScriptCDN;

            //在线总人数
            WorkContext.OnlineUserCount = OnlineUsers.GetOnlineUserCount();
            //在线游客数
            WorkContext.OnlineGuestCount = OnlineUsers.GetOnlineGuestCount();
            //在线会员数
            WorkContext.OnlineMemberCount = WorkContext.OnlineUserCount - WorkContext.OnlineGuestCount;
            //搜索词
            WorkContext.SearchWord = string.Empty;

            //设置导航列表
            //WorkContext.NavList = Navs.GetNavList();
            //设置友情链接列表
            //WorkContext.FriendLinkList = FriendLinks.GetFriendLinkList();
            //设置帮助列表
            //WorkContext.HelpList = Helps.GetHelpList();
            return(partUserInfo);
        }
Пример #18
0
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            this.ValidateRequest = false;

            WorkContext.IP = WebHelper.GetIP();
            if (WebHelper.GetQueryString("ip") == WorkContext.IP)
            {
                WorkContext.RegionInfo = Regions.GetRegionById(WebHelper.GetQueryInt("regionid"));
            }
            else
            {
                WorkContext.RegionInfo = IPSearch.SearchRegion(WorkContext.IP);
            }
            if (WorkContext.RegionInfo == null)
            {
                WorkContext.RegionInfo = new RegionInfo()
                {
                    RegionId = -1, Name = "未知区域"
                };
            }
            WorkContext.RegionId = WorkContext.RegionInfo.RegionId;

            WorkContext.Url = WebHelper.GetUrl();

            WorkContext.AppType    = WebHelper.GetQueryInt("appType");
            WorkContext.AppVersion = WebHelper.GetQueryString("appVersion");
            WorkContext.AppOS      = WebHelper.GetQueryString("appOS");

            //获得用户唯一标示符sid
            WorkContext.Sid = WebHelper.GetQueryString("sid");

            if (WorkContext.Sid.Length == 0)
            {
                //生成sid
                WorkContext.Sid = Sessions.GenerateSid();
            }

            PartUserInfo partUserInfo;

            //获得用户id
            int uid = WebHelper.GetQueryInt("uid");

            if (uid < 1)//当用户为游客时
            {
                //创建游客
                partUserInfo = Users.CreatePartGuest();
            }
            else//当用户为会员时
            {
                string encryptPwd = WebHelper.GetQueryString("encryptPwd");
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    partUserInfo = Users.CreatePartGuest();
                    encryptPwd   = string.Empty;
                }
                else
                {
                    partUserInfo = Users.GetPartUserByUidAndPwd(uid, MallUtils.DecryptCookiePassword(encryptPwd));
                    if (partUserInfo != null)
                    {
                        //发放登陆积分
                        Credits.SendLoginCredits(ref partUserInfo, DateTime.Now, TypeHelper.StringToDateTime(WebHelper.GetQueryString("slctime")), out WorkContext.SLCTime);
                    }
                    else//当会员的账号或密码不正确时,将用户置为游客
                    {
                        partUserInfo = Users.CreatePartGuest();
                        encryptPwd   = string.Empty;
                    }
                }
                WorkContext.EncryptPwd = encryptPwd;
            }

            //设置用户等级
            if (UserRanks.IsBanUserRank(partUserInfo.UserRid) && partUserInfo.LiftBanTime <= DateTime.Now)
            {
                UserRankInfo userRankInfo = UserRanks.GetUserRankByCredits(partUserInfo.PayCredits);
                Users.UpdateUserRankByUid(partUserInfo.Uid, userRankInfo.UserRid);
                partUserInfo.UserRid = userRankInfo.UserRid;
            }

            WorkContext.PartUserInfo = partUserInfo;

            WorkContext.Uid             = partUserInfo.Uid;
            WorkContext.UserName        = partUserInfo.UserName;
            WorkContext.UserEmail       = partUserInfo.Email;
            WorkContext.UserMobile      = partUserInfo.Mobile;
            WorkContext.Password        = partUserInfo.Password;
            WorkContext.NickName        = partUserInfo.NickName;
            WorkContext.Avatar          = partUserInfo.Avatar;
            WorkContext.PayCreditName   = Credits.PayCreditName;
            WorkContext.PayCreditCount  = partUserInfo.PayCredits;
            WorkContext.RankCreditName  = Credits.RankCreditName;
            WorkContext.RankCreditCount = partUserInfo.RankCredits;

            WorkContext.UserRid      = partUserInfo.UserRid;
            WorkContext.UserRankInfo = UserRanks.GetUserRankById(partUserInfo.UserRid);
            WorkContext.UserRTitle   = WorkContext.UserRankInfo.Title;
            //设置用户商城管理员组
            WorkContext.MallAGid           = partUserInfo.MallAGid;
            WorkContext.MallAdminGroupInfo = MallAdminGroups.GetMallAdminGroupById(partUserInfo.MallAGid);
            WorkContext.MallAGTitle        = WorkContext.MallAdminGroupInfo.Title;

            //设置当前控制器类名
            WorkContext.Controller = RouteData.Values["controller"].ToString().ToLower();
            //设置当前动作方法名
            WorkContext.Action  = RouteData.Values["action"].ToString().ToLower();
            WorkContext.PageKey = string.Format("/{0}/{1}", WorkContext.Controller, WorkContext.Action);

            WorkContext.ImageCDN  = WorkContext.MallConfig.ImageCDN;
            WorkContext.CSSCDN    = WorkContext.MallConfig.CSSCDN;
            WorkContext.ScriptCDN = WorkContext.MallConfig.ScriptCDN;

            //在线总人数
            WorkContext.OnlineUserCount = OnlineUsers.GetOnlineUserCount();
            //在线游客数
            WorkContext.OnlineGuestCount = OnlineUsers.GetOnlineGuestCount();
            //在线会员数
            WorkContext.OnlineMemberCount = WorkContext.OnlineUserCount - WorkContext.OnlineGuestCount;
            //购物车中商品数量
            WorkContext.CartProductCount = WebHelper.GetQueryInt("cartProductCount");
        }
Пример #19
0
 public int UpdateUserRank(UserRanks Item)
 {
     return(_dal.UpdateUserRank(Item));
 }