public ActionResult Save(Broadcast model) { model.UpdateTime = DateTime.Now; bool b = BroadcastBll.AddOrUpdateSaved(c => c.Email, model) > 0; return(ResultData(model, b, b ? "更新订阅成功!" : "更新订阅失败!")); }
public ActionResult Pass(int id) { Post post = PostBll.GetById(id); post.Status = Status.Pended; post.ModifyDate = DateTime.Now; post.PostDate = DateTime.Now; bool b = PostBll.UpdateEntitySaved(post); var cast = BroadcastBll.LoadEntities(c => c.Status == Status.Subscribed).ToList(); string link = Request.Url?.Scheme + "://" + Request.Url?.Authority + "/" + id; cast.ForEach(c => { var ts = DateTime.Now.GetTotalMilliseconds(); string content = System.IO.File.ReadAllText(Request.MapPath("/template/broadcast.html")).Replace("{{link}}", link + "?email=" + c.Email).Replace("{{time}}", post.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")).Replace("{{title}}", post.Title).Replace("{{author}}", post.Author).Replace("{{content}}", post.Content.RemoveHtmlTag(150)).Replace("{{cancel}}", Url.Action("Subscribe", "Subscribe", new { c.Email, act = "cancel", validate = c.ValidateCode, timespan = ts, hash = (c.Email + "cancel" + c.ValidateCode + ts).AESEncrypt(ConfigurationManager.AppSettings["BaiduAK"]) }, Request.Url.Scheme)); BackgroundJob.Enqueue(() => SendMail(GetSettings("Title") + "博客有新文章发布了", content, c.Email)); }); HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.UpdateLucene)); return(ResultData(null, b, b ? "审核通过!" : "审核失败!")); }
public ActionResult Change(int id) { Broadcast cast = BroadcastBll.GetById(id); Status status = cast.Status; cast.UpdateTime = DateTime.Now; cast.Status = status == Status.Subscribed ? Status.Subscribing : Status.Subscribed; bool b = BroadcastBll.UpdateEntitySaved(cast); return(ResultData(null, b, status == Status.Subscribed ? "订阅成功" : "取消订阅成功!")); }
public ActionResult Subscribe(string email) { if (bool.TryParse(GetSettings("DisabledEmailBroadcast"), out var disabled) && disabled) { return(ResultData(null, false, GetSettings("DisabledEmailBroadcastTip"))); } Broadcast entity = BroadcastBll.GetFirstEntity(b => b.Email.Equals(email, StringComparison.InvariantCultureIgnoreCase)); var guid = Guid.NewGuid(); if (entity != null) { if (entity.Status == Status.Subscribed) { return(ResultData(null, false, "您已经订阅过了,无需再重复订阅!")); } entity.ValidateCode = guid.ToString(); entity.UpdateTime = DateTime.Now; BroadcastBll.UpdateEntity(entity); } else { BroadcastBll.AddEntity(new Broadcast() { Email = email, ValidateCode = guid.ToString(), Status = Status.Subscribing, UpdateTime = DateTime.Now }); } try { var ts = DateTime.Now.GetTotalMilliseconds(); string link = Url.Action("Subscribe", "Subscribe", new { email, act = "verify", validate = guid, timespan = ts, hash = (email + "verify" + guid + ts).AESEncrypt(ConfigurationManager.AppSettings["BaiduAK"]) }, "http"); BackgroundJob.Enqueue(() => SendMail(GetSettings("Title") + "博客订阅:" + Request.Url, System.IO.File.ReadAllText(Request.MapPath("/template/subscribe.html")).Replace("{{link}}", link), email)); BroadcastBll.SaveChanges(); return(ResultData(null, message: "订阅成功,请打开您的邮箱确认操作后便可收到订阅更新!")); } catch (Exception e) { LogManager.Error(GetType(), e); return(ResultData(null, false, "订阅失败,这可能是服务器出现了一点问题,去留言板给站长反馈吧!")); } }
public ActionResult GetViewToken(string email) { if (string.IsNullOrEmpty(email) && !email.MatchEmail()) { return(ResultData(null, false, "请输入正确的邮箱!")); } if (BroadcastBll.Any(b => b.Email.Equals(email) && b.SubscribeType == SubscribeType.ArticleToken)) { var s = RedisHelper.GetString("ArticleViewToken"); Session.SetByRedis("ArticleViewToken", s); return(ResultData(null)); } return(ResultData(null, false, "您目前没有权限访问这篇文章的加密部分,请联系站长开通这篇文章的访问权限!")); }
public ActionResult GetPageData(int page = 1, int size = 10, string search = "") { List <Broadcast> list; int total; if (string.IsNullOrEmpty(search)) { list = BroadcastBll.LoadPageEntitiesFromL2CacheNoTracking(page, size, out total, b => true, b => b.UpdateTime, false).ToList(); } else { list = BroadcastBll.LoadPageEntitiesFromL2CacheNoTracking(page, size, out total, b => b.Email.Contains(search), b => b.UpdateTime, false).ToList(); } var pageCount = Math.Ceiling(total * 1.0 / size).ToInt32(); return(PageResult(list, pageCount, total)); }
public ActionResult Cancel(string email) { Broadcast c = BroadcastBll.GetFirstEntity(b => b.Email.Equals(email) && b.Status == Status.Subscribed); if (c != null) { var ts = DateTime.Now.GetTotalMilliseconds(); string url = Url.Action("Subscribe", "Subscribe", new { email, act = "cancel", validate = c.ValidateCode, timespan = ts, hash = (c.Email + "cancel" + c.ValidateCode + ts).AESEncrypt(ConfigurationManager.AppSettings["BaiduAK"]) }, Request.Url.Scheme); BackgroundJob.Enqueue(() => SendMail("取消本站订阅", $"请<a href=\"{url}\">点击这里</a>取消订阅本站更新。", email)); return(Content("取消订阅的链接已经发送到了您的邮箱,请到您的邮箱内进行取消订阅")); } return(Content("您输入的邮箱没有订阅本站更新,或者已经取消订阅了")); }
public ActionResult Subscribe(string email, string act, string validate, double timespan, string hash) { var ts = DateTime.Now.GetTotalMilliseconds(); if (ts - timespan > 86400000) { return(Content("链接已失效")); } var hash2 = (email + act + validate + timespan).AESEncrypt(ConfigurationManager.AppSettings["BaiduAK"]); if (!hash2.Equals(hash)) { return(Content("操作失败,链接已被非法篡改")); } Broadcast entity = BroadcastBll.GetFirstEntity(b => b.Email.Equals(email, StringComparison.InvariantCultureIgnoreCase) && b.ValidateCode.Equals(validate)); if (entity != null) { switch (act) { case "verify": entity.Status = Status.Subscribed; entity.ValidateCode = Guid.NewGuid().ToString(); entity.UpdateTime = DateTime.Now; BroadcastBll.UpdateEntity(entity); BroadcastBll.SaveChanges(); return(Content("订阅成功!")); case "cancel": entity.Status = Status.Canceled; entity.UpdateTime = DateTime.Now; BroadcastBll.UpdateEntity(entity); BroadcastBll.SaveChanges(); return(Content("取消订阅成功,您将不会再接收到文章更新,如果您以后需要再次接收更新推送,可以到主站点重新进行订阅操作!")); default: return(RedirectToAction("Index", "Home")); } } return(Content("该邮箱账户未使用邮件订阅!")); }
public ActionResult Write(PostInputDto post, string Seminars, DateTime?timespan, bool schedule = false) { post.Content = ReplaceImgSrc(Regex.Replace(post.Content.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/");//提取img标签,提取src属性并重新创建个只包含src属性的img标签 if (!CategoryBll.Any(c => c.Id == post.CategoryId && c.Status == Status.Available)) { return(ResultData(null, message: "请选择一个分类")); } if (string.IsNullOrEmpty(post.Label?.Trim()) || post.Label.Equals("null")) { post.Label = null; } else if (post.Label.Trim().Length > 50) { post.Label = post.Label.Replace(",", ","); post.Label = post.Label.Trim().Substring(0, 50); } else { post.Label = post.Label.Replace(",", ","); } if (!post.IsWordDocument) { post.ResourceName = null; } if (string.IsNullOrEmpty(post.ProtectContent) || post.ProtectContent.Equals("null", StringComparison.InvariantCultureIgnoreCase)) { post.ProtectContent = null; } post.Status = Status.Pended; post.PostDate = DateTime.Now; post.ModifyDate = DateTime.Now; Post p = post.Mapper <Post>(); if (!string.IsNullOrEmpty(Seminars)) { var tmp = Seminars.Split(',').Distinct(); tmp.ForEach(s => { var id = s.ToInt32(); p.Seminar.Add(SeminarBll.GetById(id)); }); } p.PostAccessRecord.Add(new PostAccessRecord() { AccessTime = DateTime.Today, ClickCount = 0 }); if (schedule) { if (timespan.HasValue && timespan.Value > DateTime.Now) { p.Status = Status.Schedule; HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.PublishPost), args: p); return(ResultData(p.Mapper <PostOutputDto>(), message: schedule ? $"文章于{timespan.Value:yyyy-MM-dd HH:mm:ss}将会自动发表!" : "文章发表成功!")); } return(ResultData(null, false, "如果要定时发布,请选择正确的一个将来时间点!")); } p = PostBll.AddEntitySaved(p); if (p != null) { var cast = BroadcastBll.LoadEntities(c => c.Status == Status.Subscribed).ToList(); string link = Request.Url?.Scheme + "://" + Request.Url?.Authority + "/" + p.Id; cast.ForEach(c => { var ts = DateTime.Now.GetTotalMilliseconds(); string content = System.IO.File.ReadAllText(Request.MapPath("/template/broadcast.html")).Replace("{{link}}", link + "?email=" + c.Email).Replace("{{time}}", post.PostDate.ToString("yyyy-MM-dd HH:mm:ss")).Replace("{{title}}", post.Title).Replace("{{author}}", post.Author).Replace("{{content}}", post.Content.RemoveHtmlTag(150)).Replace("{{cancel}}", Url.Action("Subscribe", "Subscribe", new { c.Email, act = "cancel", validate = c.ValidateCode, timespan = ts, hash = (c.Email + "cancel" + c.ValidateCode + ts).AESEncrypt(ConfigurationManager.AppSettings["BaiduAK"]) }, Request.Url.Scheme)); BackgroundJob.Schedule(() => SendMail(GetSettings("Title") + "博客有新文章发布了", content, c.Email), (p.PostDate - DateTime.Now)); }); HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.UpdateLucene)); return(ResultData(null, true, "文章发表成功!")); } return(ResultData(null, false, "文章发表失败!")); }
public ActionResult Edit(PostInputDto post, string Seminars, bool notify = true) { post.Content = ReplaceImgSrc(Regex.Replace(post.Content.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/"); if (!CategoryBll.Any(c => c.Id == post.CategoryId && c.Status == Status.Available)) { return(ResultData(null, message: "请选择一个分类")); } if (string.IsNullOrEmpty(post.Label?.Trim()) || post.Label.Equals("null")) { post.Label = null; } else if (post.Label.Trim().Length > 50) { post.Label = post.Label.Replace(",", ","); post.Label = post.Label.Trim().Substring(0, 50); } else { post.Label = post.Label.Replace(",", ","); } if (!post.IsWordDocument) { post.ResourceName = null; } if (string.IsNullOrEmpty(post.ProtectContent) || post.ProtectContent.Equals("null", StringComparison.InvariantCultureIgnoreCase)) { post.ProtectContent = null; } post.ModifyDate = DateTime.Now; Post p = PostBll.GetById(post.Id); var history = p.Mapper <PostHistoryVersion>(); p.PostHistoryVersion.Add(history); Mapper.Map(post, p); if (!string.IsNullOrEmpty(Seminars)) { var tmp = Seminars.Split(',').Distinct(); p.Seminar.Clear(); tmp.ForEach(s => { p.Seminar.Add(SeminarBll.GetFirstEntity(e => e.Title.Equals(s))); }); } bool b = PostBll.UpdateEntitySaved(p); if (b) { #if !DEBUG if (notify) { var cast = BroadcastBll.LoadEntities(c => c.Status == Status.Subscribed).ToList(); string link = Request.Url?.Scheme + "://" + Request.Url?.Authority + "/" + p.Id; cast.ForEach(c => { var ts = DateTime.Now.GetTotalMilliseconds(); string content = System.IO.File.ReadAllText(Request.MapPath("/template/broadcast.html")).Replace("{{link}}", link + "?email=" + c.Email).Replace("{{time}}", post.PostDate.ToString("yyyy-MM-dd HH:mm:ss")).Replace("{{title}}", post.Title).Replace("{{author}}", post.Author).Replace("{{content}}", post.Content.RemoveHtmlTag(150)).Replace("{{cancel}}", Url.Action("Subscribe", "Subscribe", new { c.Email, act = "cancel", validate = c.ValidateCode, timespan = ts, hash = (c.Email + "cancel" + c.ValidateCode + ts).AESEncrypt(ConfigurationManager.AppSettings["BaiduAK"]) }, Request.Url.Scheme)); BackgroundJob.Schedule(() => SendMail(GetSettings("Title") + "博客有新文章发布了", content, c.Email), (p.PostDate - DateTime.Now)); }); } #endif HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.UpdateLucene)); return(ResultData(p.Mapper <PostOutputDto>(), message: "文章修改成功!")); } return(ResultData(null, false, "文章修改失败!")); }
public ActionResult Get(int id) => ResultData(BroadcastBll.GetById(id));
public ActionResult Delete(int id) { bool b = BroadcastBll.DeleteByIdSaved(id); return(ResultData(null, b, b ? "删除订阅成功!" : "删除订阅失败!")); }