Beispiel #1
0
        private void SaveMail(string title, string[] shoujian, string content, HttpPostedFileBase file, bool isDraft, string sessionId)
        {
            string   jsonStr  = MemcachedHelper.Get(sessionId).ToString();
            UserInfo userInfo = SerializeHelper.toJson <UserInfo>(jsonStr);

            MailInfo mailInfo;

            if (file != null)
            {
                mailInfo = new MailInfo
                {
                    Title      = title,
                    Content    = content,
                    SenderId   = userInfo.ID,
                    CreateTime = DateTime.Now,
                    File       = file.FileName,
                    IsDraft    = isDraft
                };
            }
            else
            {
                mailInfo = new MailInfo
                {
                    Title      = title,
                    Content    = content,
                    SenderId   = userInfo.ID,
                    CreateTime = DateTime.Now,
                    IsDraft    = isDraft
                };
            }
            MailInfoService.AddEntity(mailInfo);
            MailInfoService.SaveMailUserInfo(shoujian, mailInfo.Id);
        }
Beispiel #2
0
        public JsonResult ActiveUser(string key)
        {
            AjaxResult result = new AjaxResult();

            if (MemcachedHelper.Get(key) != null)
            {
                string   userName = MemcachedHelper.Get(key).ToString();
                UserInfo userInfo = this._userService.GetEntity(u => u.UserName == userName);
                if (userInfo == null)
                {
                    result.Success = false;
                    result.Message = "此用户没有注册!";
                }
                else
                {
                    userInfo.Activate = "Y";
                    this._userService.Update(userInfo);
                    result.Success = true;
                }
                MemcachedHelper.Delete(key);
            }
            else
            {
                result.Success = false;
                result.Message = "此激活链接已失效!";
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            bool isSuccess = false;

            if (Request.Cookies["sessionId"] != null)
            {
                string sessionId = Request.Cookies["sessionId"].Value;
                object obj       = MemcachedHelper.Get(sessionId);
                if (obj != null)
                {
                    UserInfo userInfo = SerializeHelper.toJson <UserInfo>(obj.ToString());
                    LoginUser = userInfo;
                    isSuccess = true;
                    MemcachedHelper.Set(sessionId, obj.ToString(), DateTime.Now.AddMinutes(60));

                    if (LoginUser.UName == "123")
                    {
                        return;
                    }
                }
            }

            if (!isSuccess)
            {
                filterContext.Result = Redirect("/login/index");
            }
        }
Beispiel #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string key = Request["key"] ?? "a";

            Response.Write(string.Format("key:{0}<br/>", key));

            Response.Write(MemcachedHelper.Get(key));
            Response.Write("<br/>");
            Response.Write(MemcachedHelper.Get(key + "test"));
        }
    }
Beispiel #5
0
        public ActionResult Inbox(string query)
        {
            string   sessionId = Request.Cookies["sessionId"]?.Value ?? "";
            string   jsonStr   = MemcachedHelper.Get(sessionId).ToString();
            UserInfo userInfo  = SerializeHelper.toJson <UserInfo>(jsonStr);

            if (string.IsNullOrEmpty(query))
            {
                var mailInfos = MailInfoService.GetAllReceiveMail(userInfo.ID).ToList();
                ViewBag.MailInfoList = mailInfos;
                return(View());
            }
            else
            {
                var mailInfos = MailInfoService.GetAllReceiveMail(userInfo.ID, query).ToList();
                ViewBag.MailInfoList = mailInfos.ToList();
                return(View());
            }
        }
Beispiel #6
0
        /// <summary>
        /// 验证Session中(即Memcached中)是否有数据
        /// </summary>
        /// <returns></returns>
        public static UserInfo ValidateSession()
        {
            UserInfo userInfo  = null;
            string   sessionId = WebHelper.GetCookieValue(ConstInfo.SessionID);

            if (!string.IsNullOrEmpty(sessionId))
            {
                object value = MemcachedHelper.Get(sessionId);
                if (value != null)
                {
                    string jsonData = value.ToString();
                    userInfo = JsonConvert.DeserializeObject <UserInfo>(jsonData);
                    UserContext.LoginUser = userInfo;
                    //模拟滑动过期时间,就像Session中默认20分钟那这样
                    MemcachedHelper.Set(sessionId, value, DateTime.Now.AddHours(2));
                }
            }
            return(userInfo);
        }
Beispiel #7
0
        public ActionResult UserLogin()
        {
/*            string vCode = Session["vCode"] != null ? Session["vCode"].ToString() : "";
 *
 *          if (string.IsNullOrEmpty(vCode))
 *          {
 *              return Content("no:验证码错误");
 *          }
 *
 *          Session["vCode"] = null;
 *          string txtCode = Request["code"];
 *          if (txtCode == null)
 *          {
 *              return Content("no:验证码为空");
 *          }
 *          if (!txtCode.Equals(vCode,StringComparison.InvariantCultureIgnoreCase))
 *          {
 *              return Content("no:验证码错误");
 *          }*/


            string userName = Request["username"];
            string userPwd  = Request["password"];
            var    userInfo = UserInfoService.LoadEntities(u => u.UName == userName && u.UPwd == userPwd).FirstOrDefault();

            if (userInfo != null)
            {
                string sessionId = Guid.NewGuid().ToString();
                bool   isSuccess = MemcachedHelper.Set(sessionId, SerializeHelper.toJsonString(new{ ID = userInfo.ID, UName = userInfo.UName }), DateTime.Now.AddMinutes(200));
                string o         = MemcachedHelper.Get(sessionId).ToString();
                if (!isSuccess)
                {
                    return(Content("no:登录失败,session设置失败"));
                }
                Response.Cookies["sessionId"].Value = sessionId;
                return(Content("ok:登录成功"));
            }
            else
            {
                return(Content("no:登录失败"));
            }
        }
Beispiel #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string key   = Request["key"] ?? "a";
            string value = Request["value"] ?? "a08888";
            Response.Write(string.Format("key:{0}, value: {1}<br/>", key, value));


            if (MemcachedHelper.Set(key, value))
            {
                Response.Write("保存成功1<br/>");
            }

            Response.Write(MemcachedHelper.Get(key) + "<br/>");

            if (MemcachedHelper.Set(key + "test", value + "_test", 3))
            {
                Response.Write("保存成功2<br/>");
            }
            Response.Write(MemcachedHelper.Get(key + "test"));
            Response.Write("<br/>" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
        }
    }
Beispiel #9
0
        //[Authorize(AuthenticationSchemes = "user_info")]
        public IActionResult Index()
        {
            var userId = User.Claims.FirstOrDefault(x => x.Type == "UserName")?.Value;

            ViewData["user"] = userId;

            //throw new System.Exception("Throw Exception");
            string s    = Request.Query["s"];
            var    path = AppContext.BaseDirectory;

            #region --测试日志--
            // Logger.Info("普通信息日志-----------");
            // Logger.Debug("调试日志-----------");
            // Logger.Error("错误日志-----------");
            // Logger.Fatal("异常日志-----------");
            // Logger.Warn("警告日志-----------");
            // Logger.Trace("跟踪日志-----------");
            // Logger.Log(NLog.LogLevel.Warn, "Log日志------------------");


            // //_logger.LogInformation("你访问了首页");
            // //_logger.LogWarning("警告信息");
            // //_logger.LogError("错误信息");
            #endregion

            #region --测试redis--
            RedisHelper.Default.StringSet("redis", "redis" + DateTime.Now, TimeSpan.FromSeconds(1000000));
            ViewData["redis"] = RedisHelper.Default.StringGet("redis");
            //RedisHelper.Default.KeyDelete("redis");
            #endregion

            #region --测试sql--
            DataTable dt = Dbl.ZZCMS.CreateSqlDataTable("select * from nc_manager");
            ViewData["mng"] = dt;
            #endregion

            #region --测试memcachedcore--


            //MCached.Set("depend2", "core", "memcached-core" + DateTime.Now, 59);
            //var re = MCached.Get("depend", "core");
            //ViewData["mhelper1"] = re;

            //MemcachedHelper.Remove("core");
            MemcachedHelper.Set("core", "memcachedcore" + DateTime.Now, 10);
            var mh = MemcachedHelper.Get("core");
            ViewData["mhelper"] = mh;

            //这种方式暂未找到合适赋值,待研究,赋值赋不上。
            //删/增/取memcachedcore5
            //var cacheKey = "memcachedcore";
            //await _memcachedClient.AddAsync(cacheKey, "memcachedcore" + DateTime.Now, 60);

            ////_memcachedClient.Add(cacheKey, "memcachedcore" + DateTime.Now, 60);//此方法赋不上值
            ////var result = _memcachedClient.Get(cacheKey);
            //var result = _memcachedClient.Get(cacheKey);
            //_memcachedClient.Remove(cacheKey);
            //ViewData["memcachedcore"] = result.ToString();
            #endregion

            return(View());
        }