Example #1
0
        /// <summary>
        /// 初始化工作上下文
        /// </summary>
        protected void InitWorkContext()
        {
            WorkContext.IsHttpAjax  = WebHelper.IsAjax();
            WorkContext.IP          = WebHelper.GetIP();
            WorkContext.UrlReferrer = WebHelper.GetUrlReferrer();
            WorkContext.Url         = WebHelper.GetUrl();

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

            User user;

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

            if (uid < 1)            //当用户为游客时
            {
                //创建游客
                user = new User().CreateGuest();
            }
            else            //当用户为会员时
            {
                //获得保存在cookie中的密码
                string encryptPwd = ShopUtils.GetCookiePassword();
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    user       = new User().CreateGuest();
                    encryptPwd = string.Empty;
                    ShopUtils.SetUidCookie(-1);
                    ShopUtils.SetCookiePassword("");
                }
                WorkContext.EncryptPwd = encryptPwd;
            }

            //设置当前控制器类名
            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.SearchWord = string.Empty;
        }
Example #2
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);
        }
Example #3
0
        private PartUserInfo partUserInfo     = null;                 //用户信息

        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            ip = WebHelper.GetIP();
            //当用户ip不在允许的后台访问ip列表时
            if (!string.IsNullOrEmpty(shopConfigInfo.AdminAllowAccessIP) && !ValidateHelper.InIPList(ip, shopConfigInfo.AdminAllowAccessIP))
            {
                filterContext.Result = HttpNotFound();
                return;
            }
            //当用户IP被禁止时
            if (BannedIPs.CheckIP(ip))
            {
                filterContext.Result = HttpNotFound();
                return;
            }

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

            if (uid < 1)
            {
                uid = WebHelper.GetRequestInt("uid");
            }
            if (uid < 1)//当用户为游客时
            {
                //创建游客
                partUserInfo = Users.CreatePartGuest();
            }
            else//当用户为会员时
            {
                //获得保存在cookie中的密码
                string encryptPwd = ShopUtils.GetCookiePassword();
                if (string.IsNullOrWhiteSpace(encryptPwd))
                {
                    encryptPwd = WebHelper.GetRequestString("password");
                }
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    partUserInfo = Users.CreatePartGuest();
                    ShopUtils.SetUidCookie(-1);
                    ShopUtils.SetCookiePassword("");
                }
                else
                {
                    partUserInfo = Users.GetPartUserByUidAndPwd(uid, ShopUtils.DecryptCookiePassword(encryptPwd));
                    if (partUserInfo == null)
                    {
                        partUserInfo = Users.CreatePartGuest();
                        ShopUtils.SetUidCookie(-1);
                        ShopUtils.SetCookiePassword("");
                    }
                }
            }

            //当用户等级是禁止访问等级时
            if (partUserInfo.UserRid == 1)
            {
                filterContext.Result = HttpNotFound();
                return;
            }

            //如果当前用户没有登录
            if (partUserInfo.Uid < 1)
            {
                filterContext.Result = HttpNotFound();
                return;
            }

            //如果当前用户不是管理员
            if (partUserInfo.AdminGid == 1)
            {
                filterContext.Result = HttpNotFound();
                return;
            }
        }
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);

            WorkContext.IsHttpAjax = WebHelper.IsAjax();
            WorkContext.IP         = WebHelper.GetIP();
            //WorkContext.Region = Regions.GetRegionByIP(WorkContext.IP);
            //WorkContext.RegionId = WorkContext.Region.Id;
            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);
            }

            User user;

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

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

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

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

            //WorkContext.user = user;

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

            //WorkContext.UserRid = user.UserRid;
            //WorkContext.UserRankInfo = UserRanks.GetUserRankById(user.UserRid);
            //WorkContext.UserRTitle = WorkContext.UserRankInfo.Title;
            ////设置用户管理员组
            //WorkContext.AdminGid = user.AdminGid;
            //WorkContext.AdminGroupInfo = AdminGroups.GetAdminGroupById(user.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);

            //设置图片cdn
            WorkContext.ImageCDN = WorkContext.ShopConfig.ImageCDN;
            //设置csscdn
            WorkContext.CSSCDN = WorkContext.ShopConfig.CSSCDN;
            //设置脚本cdn
            WorkContext.ScriptCDN = WorkContext.ShopConfig.ScriptCDN;
        }
Example #5
0
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            this.ValidateRequest = false;

            WorkContext.IsHttpAjax  = WebHelper.IsAjax();
            WorkContext.IP          = WebHelper.GetIP();
            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;
            xpGrid_User user;

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

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

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

            WorkContext.User = user;

            WorkContext.Uid      = user.UserID;
            WorkContext.UserName = user.UserName;

            WorkContext.Password = user.Password;
            WorkContext.NickName = user.UserCName;

            #region 弃用


            //设置用户等级
            //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.UserEmail = user.Email;
            //WorkContext.UserMobile = partUserInfo.Mobile;

            //WorkContext.Avatar = user.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.OnlineGuestCount = OnlineUsers.GetOnlineGuestCount();
            //在线会员数
            //WorkContext.OnlineMemberCount = WorkContext.OnlineUserCount - WorkContext.OnlineGuestCount;

            ////购物车中商品数量
            //WorkContext.CartProductCount = Carts.GetCartProductCountCookie();

            ////设置导航列表
            //WorkContext.NavList = Navs.GetNavList();
            ////设置友情链接列表
            //WorkContext.FriendLinkList = FriendLinks.GetFriendLinkList();
            ////设置帮助列表
            //WorkContext.HelpList = Helps.GetHelpList();

            #endregion

            //设置当前控制器类名
            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.Dbs = WorkContext.MallConfig.Dbs;

            WorkContext.Plant = WorkContext.MallConfig.Plant;

            WorkContext.Legal = WorkContext.MallConfig.Legal;

            //string subpath = "";
            //subpath = ConfigurationManager.AppSettings["SubPath"].ToString();
            //if (subpath.Length > 0)
            //{
            //    subpath = "/" + subpath;
            //}
            //WorkContext.SubPath = subpath;

            //在线总人数
            WorkContext.OnlineUserCount = Users.GetOnlineUsersCount();
            //搜索词
            WorkContext.SearchWord = string.Empty;
        }
Example #6
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 = 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.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.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.CartProductCount = Carts.GetCartProductCountCookie();

            //设置导航列表
            WorkContext.NavList = Navs.GetNavList();
            //设置友情链接列表
            WorkContext.FriendLinkList = FriendLinks.GetFriendLinkList();
            //设置帮助列表
            WorkContext.HelpList = Helps.GetHelpList();
        }
        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 = SiteUtils.GetSidCookie();
            if (WorkContext.Sid.Length == 0)
            {
                //生成sid
                WorkContext.Sid = Sessions.GenerateSid();
                //将sid保存到cookie中
                SiteUtils.SetSidCookie(WorkContext.Sid);
            }

            PartUserInfo partUserInfo;

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

            if (uid < 1)//当用户为游客时
            {
                //创建游客
                partUserInfo = Users.CreatePartGuest();
            }
            else//当用户为会员时
            {
                //获得保存在cookie中的密码
                string encryptPwd = SiteUtils.GetCookiePassword();
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    partUserInfo = Users.CreatePartGuest();
                    encryptPwd   = string.Empty;
                    SiteUtils.SetUidCookie(-1);
                    SiteUtils.SetCookiePassword("");
                }
                else
                {
                    partUserInfo = Users.GetPartUserByUidAndPwd(uid, SiteUtils.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.UserID;
            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.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.ThemeName = WorkContext.SysConfig.ThemeName;
            //设置图片目录
            WorkContext.ImageDir = string.Format("{0}/themes/{1}/images", WorkContext.SiteConfig.ImageCDN, WorkContext.ThemeName);
            //设置css目录
            WorkContext.CSSDir = string.Format("{0}/themes/{1}/css", WorkContext.SiteConfig.CSSCDN, WorkContext.ThemeName);
            //设置脚本目录
            WorkContext.ScriptDir = string.Format("{0}/themes/{1}/scripts", WorkContext.SiteConfig.ScriptCDN, WorkContext.ThemeName);

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

            //设置导航列表
            WorkContext.NavList = ArticleClass.GetToTalNavList();
            //分类列表
            WorkContext.ClassList = ArticleClass.GetList();
            //设置友情链接列表
            WorkContext.FriendLinkList = FriendLinks.GetFriendLinkList();
            ////设置帮助列表
            //WorkContext.HelpList = Helps.GetHelpList();
        }
Example #8
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");
        }
Example #9
0
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            WorkContext.IsHttpAjax  = WebHelper.IsAjax();
            WorkContext.IP          = WebHelper.GetIP();
            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;
            xpGrid_User user;
            //获得用户id
            int uid = MallUtils.GetUidCookie();

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

            //当用户被禁止访问时重置用户为游客
            if (user.deleted == 1)
            {
                user = Users.CreatePartGuest();
                WorkContext.EncryptPwd = string.Empty;
                MallUtils.SetUidCookie(-1);
                MallUtils.SetCookiePassword("");
            }
            WorkContext.User     = user;
            WorkContext.Uid      = user.UserID;
            WorkContext.UserName = user.UserName;
            WorkContext.Password = user.Password;
            WorkContext.NickName = user.UserCName;
            ////设置当前控制器类名
            WorkContext.Controller = RouteData.Values["controller"].ToString().ToLower();
            //设置当前动作方法名
            WorkContext.Action  = RouteData.Values["action"].ToString().ToLower();
            WorkContext.PageKey = string.Format("/{0}/{1}", WorkContext.Controller, WorkContext.Action);
            //设置图片cdn
            WorkContext.ImageCDN = WorkContext.MallConfig.ImageCDN;
            //设置csscdn
            WorkContext.CSSCDN = WorkContext.MallConfig.CSSCDN;
            //设置脚本cdn
            WorkContext.ScriptCDN = WorkContext.MallConfig.ScriptCDN;

            WorkContext.Dbs = WorkContext.MallConfig.Dbs;

            WorkContext.Plant = WorkContext.MallConfig.Plant;

            WorkContext.Legal = WorkContext.MallConfig.Legal;

            string subpath = "";

            subpath = ConfigurationManager.AppSettings["SubPath"].ToString();
            if (subpath.Length > 0)
            {
                subpath = "/" + subpath;
            }
            WorkContext.SubPath = subpath;
        }
Example #10
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());
            //}
        }
Example #11
0
        protected async Task InitWorkContext()
        {
            WorkContext.IsHttpAjax  = WebHelper.IsAjax();
            WorkContext.IP          = WebHelper.GetIP();
            WorkContext.UrlReferrer = WebHelper.GetUrlReferrer();
            WorkContext.Url         = WebHelper.GetUrl();

            var regionDto = await _abpWebApiClient.PostAsync <RegionDto>(WorkContext.Url + webapiUrl + "/Region/Seek", new { ip = WorkContext.IP });

            if (regionDto == null)
            {
                WorkContext.Region   = new Region();
                WorkContext.RegionId = -1;
            }
            else
            {
                WorkContext.Region   = regionDto.MapTo <Region>();
                WorkContext.RegionId = WorkContext.Region.Id;
            }

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

            User user;

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

            if (uid < 1)            //当用户为游客时
            {
                //创建游客
                user = new User().CreateGuest();
            }
            else            //当用户为会员时
            {
                //获得保存在cookie中的密码
                string encryptPwd = ShopUtils.GetCookiePassword();
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    user       = new User().CreateGuest();
                    encryptPwd = string.Empty;
                    ShopUtils.SetUidCookie(-1);
                    ShopUtils.SetCookiePassword("");
                }
                else
                {
                    var userDto = await _abpWebApiClient.PostAsync <UserDto>(WorkContext.Url + webapiUrl + "/User/GetUserByUserIdAndPwdAsync",
                                                                             new { UserId = uid, Password = ShopUtils.DecryptCookiePassword(encryptPwd) });

                    if (userDto != null)
                    {
                        user = userDto.MapTo <User>();
                        //发放登录积分
                        //Credits.SendLoginCredits(ref user, DateTime.Now);
                    }
                    else                    //当会员的账号或密码不正确时,将用户置为游客
                    {
                        user       = new User().CreateGuest();
                        encryptPwd = string.Empty;
                        ShopUtils.SetUidCookie(-1);
                        ShopUtils.SetCookiePassword("");
                    }
                }
                WorkContext.EncryptPwd = encryptPwd;
            }

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

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

            //WorkContext.user = user;

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

            //WorkContext.UserRid = user.UserRid;
            //WorkContext.UserRankInfo = UserRanks.GetUserRankById(user.UserRid);
            //WorkContext.UserRTitle = WorkContext.UserRankInfo.Title;
            ////设置用户管理员组
            //WorkContext.AdminGid = user.AdminGid;
            //WorkContext.AdminGroupInfo = AdminGroups.GetAdminGroupById(user.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.CartProductCount = Carts.GetCartProductCountCookie();

            ////设置导航列表
            //WorkContext.NavList = Navs.GetNavList();
            ////设置友情链接列表
            //WorkContext.FriendLinkList = FriendLinks.GetFriendLinkList();
            ////设置帮助列表
            //WorkContext.HelpList = Helps.GetHelpList();
        }