浏览代码

优化文章加密内容

懒得勤快 1 周之前
父节点
当前提交
dad30b07ab

+ 3 - 1
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -204,6 +204,8 @@ public sealed class PostController : BaseController
         right.ModifyDate = right.ModifyDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
         right.ModifyDate = right.ModifyDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
         ViewBag.Ads = AdsService.GetsByWeightedPrice(2, AdvertiseType.InPage, Request.Location(), main.CategoryId, main.Label);
         ViewBag.Ads = AdsService.GetsByWeightedPrice(2, AdvertiseType.InPage, Request.Location(), main.CategoryId, main.Label);
         ViewBag.DisableCopy = post.DisableCopy;
         ViewBag.DisableCopy = post.DisableCopy;
+        left.Id = main.Id;
+        right.Id = main.Id;
         return View(new[] { main, left, right }.OrderByDescending(v => v.ModifyDate).ToArray());
         return View(new[] { main, left, right }.OrderByDescending(v => v.ModifyDate).ToArray());
     }
     }
 
 
@@ -386,7 +388,7 @@ public sealed class PostController : BaseController
     /// <param name="email"></param>
     /// <param name="email"></param>
     /// <returns></returns>
     /// <returns></returns>
     [HttpPost, ValidateAntiForgeryToken, AllowAccessFirewall, DistributedLockFilter]
     [HttpPost, ValidateAntiForgeryToken, AllowAccessFirewall, DistributedLockFilter]
-    public ActionResult GetViewToken(string email)
+    public ActionResult GetViewToken([FromBodyOrDefault] string email)
     {
     {
         var validator = new IsEmailAttribute();
         var validator = new IsEmailAttribute();
         if (!validator.IsValid(email))
         if (!validator.IsValid(email))

+ 2 - 1
src/Masuit.MyBlogs.Core/Views/Post/CompareVersion.cshtml

@@ -20,7 +20,7 @@
     }
     }
 </style>
 </style>
 <link href="~/UEditorPlus/third-party/SyntaxHighlighter/shCoreDefault.css" rel="stylesheet"/>
 <link href="~/UEditorPlus/third-party/SyntaxHighlighter/shCoreDefault.css" rel="stylesheet"/>
-<div class="container-fluid">
+<div class="container-fluid" id="postApp">
   <ol class="breadcrumb">
   <ol class="breadcrumb">
     <li>
     <li>
       <a asp-action="Index" asp-controller="Home">首页</a>
       <a asp-action="Index" asp-controller="Home">首页</a>
@@ -204,6 +204,7 @@
   </div>
   </div>
 </div>
 </div>
 <script src="~/UEditorPlus/third-party/SyntaxHighlighter/shCore.js"></script>
 <script src="~/UEditorPlus/third-party/SyntaxHighlighter/shCore.js"></script>
+<script src="/Scripts/global/article.js"></script>
 <script>
 <script>
 window.onload=function() {
 window.onload=function() {
   SyntaxHighlighter.all();
   SyntaxHighlighter.all();

+ 23 - 2
src/Masuit.MyBlogs.Core/Views/Post/ProtectContent.cshtml

@@ -6,6 +6,16 @@
 @using Masuit.Tools.Systems
 @using Masuit.Tools.Systems
 @using System.Text.RegularExpressions
 @using System.Text.RegularExpressions
 @model Masuit.MyBlogs.Core.Models.Entity.Post
 @model Masuit.MyBlogs.Core.Models.Entity.Post
+@* 管理员模式直接看 *@
+@if (Context.Session.Get<UserInfoDto>(SessionKey.UserInfo)?.IsAdmin==true) {
+  <div class="encrypted-content">
+      <p class="size20 text-center text-red">↓↓↓以下是文章加密部分↓↓↓</p>
+      @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
+  </div>
+  return;
+}
+
+@* 授权可见 *@
 @if (!string.IsNullOrEmpty(Model.ProtectContent) && Model.ProtectContentMode == ProtectContentMode.AuthorizeVisiable) {
 @if (!string.IsNullOrEmpty(Model.ProtectContent) && Model.ProtectContentMode == ProtectContentMode.AuthorizeVisiable) {
   <div class="encrypted-content" id="@SnowFlake.NewId">
   <div class="encrypted-content" id="@SnowFlake.NewId">
     @if (!string.IsNullOrEmpty(Context.Session.Get<string>("AccessViewToken")) || Context.Request.Cookies["Email"].MDString3(AppConfig.ConnString).Equals(Context.Request.Cookies["PostAccessToken"])) {
     @if (!string.IsNullOrEmpty(Context.Session.Get<string>("AccessViewToken")) || Context.Request.Cookies["Email"].MDString3(AppConfig.ConnString).Equals(Context.Request.Cookies["PostAccessToken"])) {
@@ -16,8 +26,9 @@
       <div class="comment-form">
       <div class="comment-form">
         <div class="comment-form-row" style="display:flex;gap:12px;flex-wrap:wrap;">
         <div class="comment-form-row" style="display:flex;gap:12px;flex-wrap:wrap;">
           <div style="position:relative;flex:1 1 240px;min-width:180px;display:flex;">
           <div style="position:relative;flex:1 1 240px;min-width:180px;display:flex;">
+              @Html.AntiForgeryToken()
             <input name="email" placeholder="请输入邮箱" required style="flex:1 1 auto;min-width:120px;padding-right:110px;" type="email" v-model="viewToken.email">
             <input name="email" placeholder="请输入邮箱" required style="flex:1 1 auto;min-width:120px;padding-right:110px;" type="email" v-model="viewToken.email">
-            <button :disabled="disableGetcode||!viewToken.email" @@click="getcode(viewToken.email)" class="comment-form-btn" style="position:absolute;right:2px;top:50%;transform:translateY(-50%);min-width:96px;height:36px;padding:0 8px;font-size:.97rem;z-index:2;" type="button"> {{codeMsg}} </button>
+            <button :disabled="disableGetcode||!viewToken.email" @@click="getToken(viewToken.email)" class="comment-form-btn" style="position:absolute;right:2px;top:50%;transform:translateY(-50%);min-width:96px;height:36px;padding:0 8px;font-size:.97rem;z-index:2;" type="button"> {{codeMsg}} </button>
           </div>
           </div>
           <div style="position:relative;flex:1 1 240px;min-width:180px;display:flex;">
           <div style="position:relative;flex:1 1 240px;min-width:180px;display:flex;">
             <input name="email" placeholder="验证码" required style="flex:1 1 auto;min-width:120px;padding-right:110px;" v-model="viewToken.token">
             <input name="email" placeholder="验证码" required style="flex:1 1 auto;min-width:120px;padding-right:110px;" v-model="viewToken.token">
@@ -33,19 +44,24 @@
   </div>
   </div>
   return;
   return;
 }
 }
+
+@* 评论可见 *@
 @if (!string.IsNullOrEmpty(Model.ProtectContent) && Model.ProtectContentMode == ProtectContentMode.CommentVisiable) {
 @if (!string.IsNullOrEmpty(Model.ProtectContent) && Model.ProtectContentMode == ProtectContentMode.CommentVisiable) {
   <div class="encrypted-content">
   <div class="encrypted-content">
     @if (string.IsNullOrEmpty(Context.Request.Cookies["Comment_" + Model.Id])) {
     @if (string.IsNullOrEmpty(Context.Request.Cookies["Comment_" + Model.Id])) {
       <p class="margin-bot10 size24 text-center text-red">此处内容已隐藏,评论回复后刷新页面可见</p>
       <p class="margin-bot10 size24 text-center text-red">此处内容已隐藏,评论回复后刷新页面可见</p>
     } else {
     } else {
+      <p class="size20 text-center text-red">↓↓↓以下是文章加密部分↓↓↓</p>
       @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
       @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
     }
     }
   </div>
   </div>
   return;
   return;
 }
 }
+
+@*密码科技*@
 @if (!string.IsNullOrEmpty(Model.ProtectContent) && Model.ProtectContentMode == ProtectContentMode.Password) {
 @if (!string.IsNullOrEmpty(Model.ProtectContent) && Model.ProtectContentMode == ProtectContentMode.Password) {
   <div class="encrypted-content">
   <div class="encrypted-content">
-    @if (Context.Request.Query["password"] != Model.ProtectPassword) {
+    @if (Context.Request.Query["password"].ToString() != Model.ProtectPassword) {
       <p class="margin-bot10 size24 text-center text-red">此处内容需要密码可见:</p>
       <p class="margin-bot10 size24 text-center text-red">此处内容需要密码可见:</p>
       <form class="comment-form" method="get">
       <form class="comment-form" method="get">
         <div style="position:relative;max-width:240px;">
         <div style="position:relative;max-width:240px;">
@@ -55,11 +71,14 @@
         </div>
         </div>
       </form>
       </form>
     } else {
     } else {
+      <p class="size20 text-center text-red">↓↓↓以下是文章加密部分↓↓↓</p>
       @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
       @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
     }
     }
   </div>
   </div>
   return;
   return;
 }
 }
+
+@*地区可见*@
 @if (Model.ProtectContentMode == ProtectContentMode.Regions) {
 @if (Model.ProtectContentMode == ProtectContentMode.Regions) {
   var loc = Context.Request.Location();
   var loc = Context.Request.Location();
   if (Model.ProtectContentLimitMode == RegionLimitMode.AllowRegion && Regex.IsMatch(loc + loc.Coodinate, Model.ProtectContentRegions, RegexOptions.IgnoreCase)) {
   if (Model.ProtectContentLimitMode == RegionLimitMode.AllowRegion && Regex.IsMatch(loc + loc.Coodinate, Model.ProtectContentRegions, RegexOptions.IgnoreCase)) {
@@ -72,6 +91,8 @@
     return;
     return;
   }
   }
 }
 }
+
+@*仅搜索引擎可见*@
 @if (Context.Request.IsRobot() && Model.ProtectContentLimitMode == RegionLimitMode.OnlyForSearchEngine) {
 @if (Context.Request.IsRobot() && Model.ProtectContentLimitMode == RegionLimitMode.OnlyForSearchEngine) {
   @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
   @Html.Raw(await Model.ProtectContent.ReplaceImgAttribute(Model.Title))
   return;
   return;

+ 1 - 0
src/Masuit.MyBlogs.Core/wwwroot/Content/common/style.css

@@ -2483,6 +2483,7 @@ Custom bottom spacer
 }
 }
 
 
 .encrypted-content {
 .encrypted-content {
+  line-height: 1.84;
   background: #f9f6ff;
   background: #f9f6ff;
   border: 1.5px dashed #b7971e;
   border: 1.5px dashed #b7971e;
   color: #b7971e;
   color: #b7971e;

+ 28 - 0
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/article.js

@@ -338,6 +338,34 @@ createApp({
         this.disableGetcode = false;
         this.disableGetcode = false;
       }
       }
     },
     },
+    async getToken(email) {
+      message.info('正在发送验证码,请稍候...');
+      const data = await axios.create({
+        headers: {
+          'RequestVerificationToken': document.querySelector('input[name="__RequestVerificationToken"]').value
+        }
+      }).post("/post/GetViewToken", {
+        email: email
+      }).then(res => res.data);
+      if (data.Success) {
+        this.disableGetcode = true;
+        message.success('验证码发送成功,请注意查收邮件,若未收到,请检查你的邮箱地址或邮件垃圾箱!');
+        localStorage.setItem("user", JSON.stringify({ NickName: this.reply.NickName || this.msg.NickName, Email: this.reply.Email || this.msg.Email }));
+        var count = 0;
+        var timer = setInterval(() => {
+          count++;
+          this.codeMsg = '重新发送(' + (120 - count) + ')';
+          if (count > 120) {
+            clearInterval(timer);
+            this.disableGetcode = false;
+            this.codeMsg = '重新发送';
+          }
+        }, 1000);
+      } else {
+        message.error(data.Message);
+        this.disableGetcode = false;
+      }
+    },
     replyMsg(item) {
     replyMsg(item) {
       this.reply.ParentId = item.Id;
       this.reply.ParentId = item.Id;
       this.reply.for = item;
       this.reply.for = item;