public ActionResult Index()
        {
            if (true)
            {
                var user = _user.GetUserInfo("admin", StringHelper.GetMd5("123123"));//StringHelper.GetMd5(userPassWord)

                //更新用户登录信息
                string userIP = WebCommon.GetIPAddress();
                int    result = _user.UpdateUserLoginInfo(user.Id, userIP);
                //唯一标识ID
                string userGuid = WebCommon.GetOnlyCode();
                //拼接cookies字符串
                var userData = user.Id + "|" + user.UserName + "|" + user.UserNickName + "|" + user.UserType + "|" + user.RegistIP + "|" + userIP + "|" + userGuid;
                //用户信息写入cookies
                FormsAuthentication.SetAuthCookie(userData, false);
                var cookie = new HttpCookie("remember");
                cookie.Value = userData;
                Response.Cookies.Add(cookie);

                string resultStr = OperatorHelper.Instance.AddLoginUser(user.UserName, Entity.Enum.ReadonlyKey.LoginAppId);//写入缓存信息

                return(RedirectToAction("index", "Home"));
            }

            return(View());
        }
Esempio n. 2
0
        private void GetlogEntity()
        {
            logEntity.F_LogId          = Guid.NewGuid().ToString();
            logEntity.F_OperateAccount = Passport.Current.UserName + "(" + Passport.Current.UserNickName + ")";
            logEntity.F_OperateUserId  = Passport.Current.UserId.ToString();
            logEntity.F_OperateTime    = DateTime.Now;
            logEntity.F_IPAddress      = WebCommon.GetIPAddress();
            logEntity.F_Host           = WebHelper.Host;
            logEntity.F_Browser        = WebCommon.GetClientBrowserVersions();

            logEntity.F_DeleteMark = false;
        }
Esempio n. 3
0
        private void GetlogEntity()
        {
            logEntity.F_LogId = Guid.NewGuid().ToString();
            System.Web.Caching.Cache objCache = HttpRuntime.Cache;

            logEntity.F_OperateAccount = ((T_User)objCache["session_user"]).userId.ToString();
            logEntity.F_OperateUserId  = Passport.Current.UserId.ToString();
            logEntity.F_OperateTime    = DateTime.Now;
            logEntity.F_IPAddress      = WebCommon.GetIPAddress();
            logEntity.F_Host           = WebHelper.Host;
            logEntity.F_Browser        = WebCommon.GetClientBrowserVersions();

            logEntity.F_DeleteMark = false;
        }
Esempio n. 4
0
        public ActionResult ShopDetails()
        {
            int id        = Convert.ToInt32(Request["id"]);
            var bookmodel = booksbll.LoadEntities(c => c.Id == id).FirstOrDefault();

            if (bookmodel != null)
            {
                //查找相关图书
                var combook = booksbll.LoadEntities(c => c.Categories.PId == bookmodel.Categories.PId && c.Id != id).OrderByDescending(c => c.Id).Skip <Books>(0).Take <Books>(12).ToList();
                //查看评论内容
                int page;
                if (!int.TryParse(Request["page"], out page))
                {
                    page = 1;
                }
                page = page < 1 ? 1 : page;
                int pagesize = 5;
                int count    = commentbll.LoadEntities(c => c.BookId == id).Count();
                if (count > 0)
                {
                    ViewBag.TotalCount = count;
                }
                int pageCount = commentbll.GetPageCount(pagesize, id);
                if (pageCount > 0)
                {
                    page = page > pageCount ? pageCount : page;
                    var commentmodel = commentbll.LoadPageEntities <int>(page, pagesize, c => c.BookId == id, c => c.Id, false).ToList();
                    ViewData["comment"] = commentmodel;
                    ViewBag.PageCount   = pageCount;
                }
                ViewData["bookmodel"] = bookmodel;

                #region 推荐
                List <Books> newblist = new List <Books>();
                //冷启动
                //首先查找购买此图书的用户还购买过的商品
                var order = orderbookbll.LoadEntities(c => c.BookID == id).GroupBy(c => c.Orders.UserId).ToList();
                foreach (var item in order)
                {
                    var blist = orderbookbll.LoadEntities(c => c.Orders.UserId == item.Key && c.BookID != id).GroupBy(c => c.BookID).ToList();
                    foreach (var citem in blist)
                    {
                        //过滤自己购买过的图书
                        if (Session["user"] != null)
                        {
                            Users user   = Session["user"] as Users;
                            var   myself = orderbookbll.LoadEntities(c => c.BookID == citem.Key && c.Orders.UserId == user.Id).FirstOrDefault();
                            if (myself != null)
                            {
                                continue;
                            }
                        }
                        var bmodel = booksbll.LoadEntities(c => c.Id == citem.Key).FirstOrDefault();
                        newblist.Add(bmodel);
                    }
                }
                #endregion

                ViewData["combook"] = newblist.OrderByDescending(c => c.rating).Skip(0).Take(12).Count() <= 0 ? combook : newblist.OrderByDescending(c => c.rating).Skip(0).Take(12).ToList();

                ViewBag.PageIndex = page;
                ViewBag.Id        = id;
            }
            else
            {
                Response.Redirect("/Home/Index");
            }

            if (Session["user"] != null)
            {
                Users user = Session["user"] as Users;
                logbll.AddUserOperationLog(user.Id, id, "浏览", "时间:" + DateTime.Now + " 地点:商品详情", "", "");
            }


            #region 浏览记录
            //记录ip地址
            string ip = WebCommon.GetIPAddress();

            //查询是否存在此数据
            var isip = hotbll.LoadEntities(c => c.bookID == id && c.ipAddress == ip).FirstOrDefault();
            if (isip == null)
            {
                HotCount hot = new HotCount();
                hot.bookID    = id;
                hot.ipAddress = ip;
                hot.addTime   = DateTime.Now;
                hotbll.AddEntity(hot);

                var count = hotbll.LoadEntities(c => c.bookID == id).Count();
                bookmodel.hotcount = count;
                booksbll.UpdateEntity(bookmodel);
            }
            #endregion

            #region 最近浏览cookie
            if (Request.Cookies["bookrecord"] != null && Request.Cookies["bookrecord"].Value.IndexOf(',') != -1)
            {
                string[] str    = Request.Cookies["bookrecord"].Value.Split(',');
                bool     exists = ((IList)str).Contains(id.ToString());
                if (!exists)//
                {
                    string     strid = id + "," + Request.Cookies["bookrecord"].Value;
                    HttpCookie ck1   = new HttpCookie("bookrecord", strid);
                    ck1.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(ck1);
                }
            }
            else
            {
                string     bookstr = id + ",";
                HttpCookie ck1     = new HttpCookie("bookrecord", bookstr);
                ck1.Expires = DateTime.Now.AddDays(30);
                Response.Cookies.Add(ck1);
            }


            #endregion

            return(View());
        }
        public bool UserLogin(string userName, string userPassWord, string checkCode, out string msg)
        {
            if (string.IsNullOrEmpty(userName.Trim()))
            {
                msg = "登录失败,用户名不能为空";
                return(false);
            }
            if (string.IsNullOrEmpty(userPassWord.Trim()))
            {
                msg = "登录失败,用户密码不能为空";
                return(false);
            }
            if (string.IsNullOrEmpty(checkCode.Trim()))
            {
                msg = "登录失败,验证码不能为空";
                return(false);
            }
            try
            {
                string code = WebHelper.GetSession("session_verifycode");
                if (code.ToLower() != checkCode.ToLower())
                {
                    msg = "登录失败,验证码错误";
                    return(false);
                }
                var user = _user.GetUserInfo(userName, userPassWord);//StringHelper.GetMd5(userPassWord)
                if (user == null)
                {
                    msg = "登录失败,用户名或密码不正确";
                    return(false);
                }
                if (user.Valid == StructDictCode.状态.注销)
                {
                    msg = "登录失败,该用户已经注销";
                    return(false);
                }
                //更新用户登录信息
                string userIP = WebCommon.GetIPAddress();
                int    result = _user.UpdateUserLoginInfo(user.Id, userIP);
                //唯一标识ID
                string userGuid = WebCommon.GetOnlyCode();
                //拼接cookies字符串
                var userData = user.Id + "|" + user.UserName + "|" + user.UserNickName + "|" + user.UserType + "|" + user.RegistIP + "|" + userIP + "|" + userGuid;
                //用户信息写入cookies
                FormsAuthentication.SetAuthCookie(userData, false);
                var cookie = new HttpCookie("remember");
                cookie.Value = userData;
                Response.Cookies.Add(cookie);

                string resultStr = OperatorHelper.Instance.AddLoginUser(user.UserName, Entity.Enum.ReadonlyKey.LoginAppId);//写入缓存信息
                WebSecurityHelper.LogCommon.Current.WriteLog_Login(true, true);
                msg = "登录成功";
                //删除验证码
                WebHelper.RemoveSession("session_verifycode");
                return(true);
            }
            catch (Exception ex)
            {
                msg = "登录失败,网络异常";
                LogCommon.Current.WriteLog_Exception(msg + "===" + ex.Message);
                LogHelper.Error(ex);
                throw ex;
            }
        }