public JsonResult ResetPassword(string active, ResetPwd resetPwd) { var data = new { code = 1, msg = "修改失败" }; if (!string.IsNullOrEmpty(active) && ModelState.IsValid) { if (TempData[Keys.ValidCode] == null || !TempData[Keys.ValidCode].ToString().Equals(resetPwd.Code, StringComparison.CurrentCultureIgnoreCase)) { data = new { code = 1, msg = "验证码错误" }; //Session[Keys.ValidCode] = null; return(Json(data)); } var obj = MemcacheHelper.Get(active); if (obj != null) { var user = SerializerHelper.DeserializeToObject <User>(obj.ToString()); if (user != null) { user.Login_Password = resetPwd.Password.Md5_32(); userService.EditEntity(user); if (userService.SaveChanges()) { data = new { code = 0, msg = "修改成功,请牢记新密码。" }; MemcacheHelper.Set(active, null, DateTime.Now.AddHours(-1)); } } } } return(Json(data)); }
//将文件中的日志备份数据写入到Appender中 static void ReadBackupLogInFileToAppender() { string path = GetWholeFolderPath(FileType.Backup); if (!Directory.Exists(path)) { return; } string[] allFiles = Directory.GetFiles(path, "*.log"); List <int> errIndex = new List <int>(); for (int i = 0; i < allFiles.Length; i++) { if (errIndex.Count >= 2 && errIndex[0] == 0 && errIndex[1] == 1) //连续两个失败,则退出 { logReadThreadSleepNum *= 2; //循环时间延长 if (allFiles.Length > logBackupWarnNum) { logReadThreadSleepNum *= 10;//循环时间延长 throw new Exception("系统中备份的日志数据已达到【" + allFiles.Length + "】条,请确认日志收集系统的队列服务工作正常。"); } break; } var item = allFiles[i]; var curText = System.IO.File.ReadAllText(item); object model = null; var bOK = false; if (item.Contains("_" + MQType.MonitorLog.ToString() + ".log")) { model = SerializerHelper.DeserializeToObject <Log_SystemMonitorMQ>(curText); //不能是Log_SystemMonitorR bOK = appender.WriteLogAgain(model); } else if (item.Contains("_" + MQType.TraceLog.ToString() + ".log") || item.Contains("_" + MQType.TraceLogEx.ToString() + ".log")) { model = SerializerHelper.DeserializeToObject <Log_OperateTrace>(curText); //不能是Log_OperateTraceR bOK = appender.WriteLogAgain(model); } if (bOK) { System.IO.File.Delete(item); Thread.Sleep(500); } else { errIndex.Add(i); Thread.Sleep(5000); } } }
/// <summary> /// 获取当前登陆人的账户信息 /// </summary> /// <returns>账户信息</returns> protected Account GetCurrentAccount() { if (Request.Cookies[Keys.SessionId] != null) { string sessionId = Request.Cookies[Keys.SessionId].Value;//接收从Cookie中传递过来的Memcache的key if (sessionId != null) { object obj = MemcacheHelper.Get(sessionId);//根据key从Memcache中获取用户的信息 return(obj == null ? null : SerializerHelper.DeserializeToObject <Account>(obj.ToString())); } } Redirect("/account/signin"); return(null); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var request = filterContext.HttpContext.Request; var response = filterContext.HttpContext.Response; // 判断是否跳过登录验证 if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), false)) { return; } if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), false)) { return; } var cookie = request.Cookies[Keys.SessionId]; if (cookie != null) { var sessionid = request.Cookies[Keys.SessionId]?.Value; if (sessionid != null) { var obj = MemcacheHelper.Get(sessionid); if (obj != null) { var account = SerializerHelper.DeserializeToObject <Account>(obj.ToString()); if (account != null) { // 滑动过期时间 cookie.Expires = DateTime.Now.AddHours(1); cookie.HttpOnly = true; response.Cookies.Add(cookie); MemcacheHelper.Set(sessionid, obj, DateTime.Now.AddHours(1)); Account = account; return; } } } } if (request.IsAjaxRequest()) { filterContext.Result = new AjaxUnauthorizedResult(); return; } response.StatusCode = 401; var from = filterContext.HttpContext.Server.UrlEncode(filterContext.HttpContext.Request.Url.ToString()); filterContext.Result = new RedirectResult($"/account/signin?returnUrl={from}"); base.OnActionExecuting(filterContext); }
public List <Article_Category> GetCategories() { List <Article_Category> categories = null; var obj = MemcacheHelper.Get(Keys.Categories); if (obj != null) { categories = SerializerHelper.DeserializeToObject <List <Article_Category> >(obj.ToString()); } if (categories == null) { categories = categoryRepository.LoadEntities(c => true).OrderBy(c => c.Sort).ToList(); MemcacheHelper.Set(Keys.Categories, SerializerHelper.SerializeToString(categories)); } return(categories); }
public List <Favorites> CurrentUserFavorites(long userId) { List <Favorites> favorites = null; var obj = MemcacheHelper.Get(userId.ToString()); if (obj != null) { favorites = SerializerHelper.DeserializeToObject <List <Favorites> >(obj.ToString()); } else { favorites = favoritesRepository.LoadEntities(f => f.User_Id == userId)?.ToList(); MemcacheHelper.Set(userId.ToString(), SerializerHelper.SerializeToString(favorites), DateTime.Now.AddMinutes(10)); } return(favorites); }
public List <FriendLinks> GetFriendLinks() { List <FriendLinks> friendLinks = null; var obj = MemcacheHelper.Get(Keys.FriendLinks); if (obj != null) { friendLinks = SerializerHelper.DeserializeToObject <List <FriendLinks> >(obj.ToString()); } if (friendLinks == null) { friendLinks = friendLinksRepository.LoadEntities(f => true).OrderBy(f => f.Sort)?.ToList(); MemcacheHelper.Set(Keys.FriendLinks, SerializerHelper.SerializeToString(friendLinks), DateTime.Now.AddHours(24)); } return(friendLinks); }
public ActionResult ResetPassword(string active) { if (!string.IsNullOrEmpty(active)) { var obj = MemcacheHelper.Get(active); if (obj != null) { var user = SerializerHelper.DeserializeToObject <User>(obj.ToString()); if (user != null) { ViewBag.Active = active; return(View()); } } } ViewBag.Error = "重置密码链接失效,请重新找回密码"; return(View("ForgetPassword")); }
/// <summary> /// 当Action中标注了[LoginFilter]的时候会执行 /// </summary> /// <param name="filterContext">请求上下文</param> public override void OnActionExecuting(ActionExecutingContext filterContext) { //if (filterContext.HttpContext.Session["account"] == null) //{ // filterContext.HttpContext.Response.Write(" <script type='text/javascript'> window.top.location='Login'; </script>"); // filterContext.Result = new EmptyResult(); // return; //} base.OnActionExecuting(filterContext); bool result = false; if (filterContext.HttpContext.Request.Cookies["sessionId"] != null) { string sessionId = filterContext.HttpContext.Request.Cookies["sessionId"]; //接收从Cookie中传递过来的Memcache的key object obj = Common.MemcacheHelper.Get(sessionId); //根据key从Memcache中获取用户的信息 if (obj != null) { var account = SerializerHelper.DeserializeToObject <Account>(obj.ToString()); if (account == null) { result = true; } } else { result = true; } } else { result = true; } if (result) { //filterContext.HttpContext.Response.Write(" <script type='text/javascript'> window.top.location='Login'; </script>"); filterContext.HttpContext.Response.Redirect("/Login"); filterContext.Result = new EmptyResult(); return; } }
public JsonResult ValidEmail(string confirmatio) { var data = new { code = 1, msg = "验证失败,请重试!", error = "" }; if (!string.IsNullOrEmpty(confirmatio)) { var obj = MemcacheHelper.Get(confirmatio); if (obj != null) { var user = SerializerHelper.DeserializeToObject <User>(obj.ToString()); if (user != null) { // 邮箱验证成功 user.IsValid = true; userService.EditEntity(user); if (userService.SaveChanges()) { MemcacheHelper.Delete(confirmatio); var sessionid = Guid.NewGuid().ToString(); MemcacheHelper.Set(sessionid, SerializerHelper.SerializeToString(user.ToAccount()), DateTime.Now.AddHours(1)); Response.Cookies[Keys.SessionId].Value = sessionid; Response.Cookies[Keys.SessionId].Expires = DateTime.Now.AddHours(1); data = new { code = 0, msg = "成功绑定邮箱。", error = "" }; } } else { data = new { code = 1, msg = "验证失败,请重试!", error = "用户不存在。" }; } } else { data = new { code = 1, msg = "验证失败,请重试!", error = "验证信息过期。" }; } } return(Json(data)); }
public ActionResult BrowseBy(int?pageIndex) { HttpCookie cookies = Request.Cookies["QuickSearchModel"]; int index = pageIndex ?? 1; if (cookies != null) { List <BannerAutoModel> lists = new List <BannerAutoModel>(); var value = cookies.Values["Options"]; var model = SerializerHelper.DeserializeToObject <QuickSearchModel>(value); if (!string.IsNullOrEmpty(value) && model != null) { var result = AutoService.GetSet().AsQueryable(); if (!string.IsNullOrEmpty(model.Brand)) { result = result.Where(r => r.Brand.Name == model.Brand); } if (!string.IsNullOrEmpty(model.Brand)) { result = result.Where(r => r.Brand.Name == model.Brand); } if (model.MinYear != null && model.MinYear <= model.MaxYear) { result = result.Where(r => r.Year > model.MinYear); } if (model.MaxYear != null && model.MaxYear >= model.MinYear) { result = result.Where(r => r.Year <= model.MaxYear); } if (!string.IsNullOrEmpty(model.Style)) { result = result.Where(r => r.BodyStyle == model.Style); } if (!string.IsNullOrEmpty(model.Transmission)) { result = result.Where(r => r.Transmission == model.Transmission); } var list = result.ToList(); model.PageTotal = list.Count(); model.PageIndex = index; model.PageCount = 6; HttpCookie cookie = new HttpCookie("QuickSearchModel"); DateTime dt = DateTime.Now; TimeSpan ts = new TimeSpan(0, 1, 0, 0, 0); cookie.Expires = dt.Add(ts); cookie.Values.Add("Options", SerializerHelper.SerializerToString(model)); Response.AppendCookie(cookie); var cars = result.Skip(index).Take(9).ToList(); ViewBag.SearchModel = model; return(View(lists)); } } var bannerCars = AutoService.GetCars(index, 6).ToList(); List <BannerAutoModel> banners = new List <BannerAutoModel>(); bannerCars.ForEach(b => { var banner = new BannerAutoModel(); banner.AutoId = b.ID; banner.Brand = b.Brand.Name; banner.Maker = b.Maker.Name; banner.Mileage = b.Mileage; banner.img.Url = b.Img.FirstOrDefault(i => i.Type == ImgType.Banner).Address; banner.Price = b.Price; banner.Sort = b.Sort; banner.Style = b.BodyStyle; banners.Add(banner); }); return(View(banners)); }