瀏覽代碼

数据写保护开关

懒得勤快 6 年之前
父節點
當前提交
715c6f7ec9

+ 5 - 0
src/Masuit.MyBlogs.Core/Controllers/BaseController.cs

@@ -94,6 +94,11 @@ namespace Masuit.MyBlogs.Core.Controllers
                 filterContext.Result = RedirectToAction("ComingSoon", "Error");
             }
 
+            if (filterContext.HttpContext.Request.Method.Equals(HttpMethods.Post) && CommonHelper.SystemSettings.GetOrAdd("DataReadonly", "false") == "true")
+            {
+                filterContext.Result = ResultData("网站当前处于数据写保护状态,无法提交任何数据,如有疑问请联系网站管理员!", false, "网站当前处于数据写保护状态,无法提交任何数据,如有疑问请联系网站管理员!", user != null, HttpStatusCode.BadRequest);
+            }
+
             if (user == null && Request.Cookies.Any(x => x.Key == "username" || x.Key == "password")) //执行自动登录
             {
                 string name = Request.Cookies["username"];

+ 24 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/system.js

@@ -126,6 +126,7 @@
 			swal('服务请求失败','','error');
 		}).catch(swal.noop);
 	}
+
 	$scope.DisabledEmailBroadcast= function() {
 		if($scope.Settings.DisabledEmailBroadcast=="true") {
 			$scope.Settings.DisabledEmailBroadcast="false";
@@ -133,6 +134,7 @@
 			$scope.Settings.DisabledEmailBroadcast="true";
 		}
 	}
+
 	$scope.CloseSite= function() {
 		if($scope.Settings.CloseSite=="true") {
 			$scope.Settings.CloseSite="false";
@@ -154,6 +156,28 @@
 			});
 		}
 	}
+
+	$scope.DataReadonly= function() {
+		if($scope.Settings.DataReadonly=="true") {
+			$scope.Settings.DataReadonly="false";
+		} else {
+			swal({
+				title: '确定要开启站点写保护么?',
+				text: "一旦开启,前台所有表单数据将无法被提交!",
+				type: 'warning',
+				showCancelButton: true,
+				confirmButtonColor: '#3085d6',
+				cancelButtonColor: '#d33',
+				confirmButtonText: '确定',
+				cancelButtonText: '取消',
+			}).then(function(isConfirm) {
+				if (isConfirm) {
+					$scope.Settings.DataReadonly = "true";
+					$scope.$apply();
+				}
+			});
+		}
+	}
 }]);
 myApp.controller("log", ["$scope", "$http", function ($scope, $http) {
 	window.hub.stop();

+ 7 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/system/home.html

@@ -42,6 +42,13 @@
                 <span class="el-switch-style" ng-click="CloseSite()"></span>
             </span>
         </div>
+        <div class="input-group">
+            <span class="input-group-addon el-switch" style="text-align: left">
+                <span>数据写保护:</span>
+                <input type="checkbox" name="switch" ng-checked="Settings.DataReadonly=='true'">
+                <span class="el-switch-style" ng-click="DataReadonly()"></span>
+            </span>
+        </div>
         <div class="input-group">
             <span class="input-group-addon">资源管理器根目录:</span>
             <div class="fg-line">