From 309b6962668ffbef7a978ae3ec064aa5c0e78122 Mon Sep 17 00:00:00 2001 From: "DESKTOP-CLI22EN\\HogenWang" Date: Wed, 18 Apr 2018 00:27:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=B3=BB=E7=BB=9F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E5=A2=9E=E5=8A=A0404=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminCP/Controllers/SystemController.cs | 152 ++++++++++++++++++ .../AdminCP/Views/System/AttachConfig.cshtml | 147 +++++++++++++++++ .../Areas/AdminCP/Views/System/Robots.cshtml | 40 +++++ .../AdminCP/Views/System/SmtpConfig.cshtml | 89 ++++++++++ .../Controllers/StatusCodeController.cs | 21 +++ COMCMS.Web/Startup.cs | 2 + COMCMS.Web/Views/StatusCode/Index.cshtml | 73 +++++++++ 7 files changed, 524 insertions(+) create mode 100644 COMCMS.Web/Areas/AdminCP/Views/System/AttachConfig.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/System/Robots.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml create mode 100644 COMCMS.Web/Controllers/StatusCodeController.cs create mode 100644 COMCMS.Web/Views/StatusCode/Index.cshtml diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs index 21e0cb0..06a1c07 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs @@ -8,12 +8,21 @@ using COMCMS.Core; using XCode; using Newtonsoft.Json; using COMCMS.Web.Common; +using COMCMS.Core.Models; +using Microsoft.AspNetCore.Hosting; +using System.IO; namespace COMCMS.Web.Areas.AdminCP.Controllers { [Area("AdminCP")] public class SystemController : AdminBaseController { + private IHostingEnvironment _env; + public SystemController(IHostingEnvironment env) + { + _env = env; + } + #region 系统基本设置 [MyAuthorize("view", "baseconfig")] public IActionResult BaseConfig() @@ -51,5 +60,148 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers } #endregion + + #region SMTP 配置 + [MyAuthorize("view", "smptconfig")] + public IActionResult SmtpConfig() + { + Config cfg = Config.GetSystemConfig(); + SMTPConfigEntity smtp = cfg.SMTPConfigEntity; + Admin.WriteLogActions("查看SMTP配置;"); + return View(smtp); + } + + [HttpPost] + [MyAuthorize( "view", "smptconfig", "JSON")] + public IActionResult SmtpConfig(SMTPConfigEntity model) + { + //验证 + if (!Utils.IsValidEmail(model.SmtpEmail)) + { + tip.Message = "SMTP帐号格式错误!请输入正确的Email!"; + return Json(tip); + } + if (string.IsNullOrEmpty(model.SmtpHost)) + { + tip.Message = "请输入SMTP服务器地址!"; + return Json(tip); + } + if (!Utils.IsInt(model.SmtpProt)) + { + tip.Message = "请输入正确的端口号!"; + return Json(tip); + } + string json = JsonConvert.SerializeObject(model); + + OtherConfig oc = OtherConfig.Find(OtherConfig._.ConfigName == "smtp"); + + if (oc == null)//如果不存在 + { + oc = new OtherConfig(); + oc.ConfigName = "smtp"; + oc.ConfigValue = JsonConvert.SerializeObject(model); + oc.LastUpdateTime = DateTime.Now; + oc.Insert(); + } + else + { + oc.ConfigValue = JsonConvert.SerializeObject(model); + oc.LastUpdateTime = DateTime.Now; + oc.Update(); + } + Admin.WriteLogActions("修改SMTP设置;"); + + tip.Status = JsonTip.SUCCESS; + tip.Message = "修改站点SMTP配置成功"; + + return Json(tip); + } + + #endregion + + #region 附件配置 + [MyAuthorize( "view", "attachconfig")] + public IActionResult AttachConfig() + { + Config cfg = Config.GetSystemConfig(); + AttachConfigEntity model = cfg.AttachConfigEntity; + Admin.WriteLogActions("查看附件配置;"); + return View(model); + } + + [HttpPost] + [MyAuthorize("view", "attachconfig", "JSON")] + public IActionResult AttachConfig(AttachConfigEntity model) + { + if (!string.IsNullOrWhiteSpace(model.WaterMarkImg)) + { + + if (!System.IO.File.Exists(Path.Combine(_env.WebRootPath, model.WaterMarkImg))) + { + tip.Message = "水印图片不存在,请重新上传!"; + return Json(tip); + } + } + string json = JsonConvert.SerializeObject(model); + + OtherConfig oc = OtherConfig.Find(OtherConfig._.ConfigName == "attach"); + + if (oc == null)//如果不存在 + { + oc = new OtherConfig(); + oc.ConfigName = "attach"; + oc.ConfigValue = json; + oc.LastUpdateTime = DateTime.Now; + oc.Insert(); + } + else + { + oc.ConfigValue = json; + oc.LastUpdateTime = DateTime.Now; + oc.Update(); + } + Admin.WriteLogActions("修改附件配置;"); + tip.Status = JsonTip.SUCCESS; + tip.Message = "修改附件配置成功"; + return Json(tip); + } + #endregion + + #region robots设置 + [HttpGet] + [MyAuthorize("view","robots" )] + public IActionResult Robots() + { + //获取文件内容 + string file = Path.Combine(_env.WebRootPath, "robots.txt"); + string content = ""; + if (System.IO.File.Exists(file)) + { + content = System.IO.File.ReadAllText(file); + } + ViewBag.content = content; + Admin.WriteLogActions("查看Robots.txt;"); + return View(); + } + [HttpPost] + [MyAuthorize("edit", "robots", "JSON")] + public IActionResult Robots(string content) + { + string file = Path.Combine(_env.WebRootPath, "robots.txt"); + if (System.IO.File.Exists(file)) + { + //写入覆盖 + System.IO.File.WriteAllText(file, content); + } + else + { + System.IO.File.WriteAllText(file, content); + } + tip.Status = JsonTip.SUCCESS; + tip.Message = "修改Robots.txt成功"; + Admin.WriteLogActions("修改Robots.txt成功;"); + return Json(tip); + } + #endregion } } \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Views/System/AttachConfig.cshtml b/COMCMS.Web/Areas/AdminCP/Views/System/AttachConfig.cshtml new file mode 100644 index 0000000..090fb8d --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/System/AttachConfig.cshtml @@ -0,0 +1,147 @@ +@model COMCMS.Core.Models.AttachConfigEntity +@{ + ViewBag.title = "编辑网站附件设置"; +} +
+
+
+
@ViewBag.Title
+
+
+
+
+ @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editAttachConfigForm", @class = "form-horizontal m-t" })) + { +
+ +
+ +
+
+ +
+ +
+ + X + +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + X + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+

+ + + +

+

+ + + +

+

+ + + +

+ +
+
+
+
+
+ +
+
+ } +
+
+ + +
+ \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Views/System/Robots.cshtml b/COMCMS.Web/Areas/AdminCP/Views/System/Robots.cshtml new file mode 100644 index 0000000..e319d63 --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/System/Robots.cshtml @@ -0,0 +1,40 @@ + +@{ + ViewBag.title = "查看/编辑Robots配置"; +} +
+
+
+
@ViewBag.Title
+
+
+
+
+
+
+ +

注意:本选项仅供专业人士使用,请不要擅自修改,否则,网站将可能正常被搜索引擎收录!

+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+ + +
+ \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml b/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml new file mode 100644 index 0000000..b9953a0 --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml @@ -0,0 +1,89 @@ +@model COMCMS.Core.Models.SMTPConfigEntity +@{ + ViewBag.title = "编辑网站SMTP设置"; +} + +
+
+
+ +
+
+
+ @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editBaseConfigForm", @class = "form-horizontal m-t" })) + { +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+
+ } +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+ +
+ +
+ + diff --git a/COMCMS.Web/Controllers/StatusCodeController.cs b/COMCMS.Web/Controllers/StatusCodeController.cs new file mode 100644 index 0000000..ac2147f --- /dev/null +++ b/COMCMS.Web/Controllers/StatusCodeController.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Diagnostics; +using Microsoft.AspNetCore.Mvc; + +namespace COMCMS.Web.Controllers +{ + public class StatusCodeController : Controller + { + [HttpGet("/StatusCode/{statusCode}")] + public IActionResult Index(int statusCode) + { + var reExecute = HttpContext.Features.Get(); + NewLife.Log.XTrace.WriteLine($"Unexpected Status Code: {statusCode}, OriginalPath: {reExecute.OriginalPath}"); + ViewBag.url = ""; + return View(statusCode); + } + } +} \ No newline at end of file diff --git a/COMCMS.Web/Startup.cs b/COMCMS.Web/Startup.cs index 14baf43..f82d0a9 100644 --- a/COMCMS.Web/Startup.cs +++ b/COMCMS.Web/Startup.cs @@ -68,6 +68,8 @@ namespace COMCMS.Web { app.UseExceptionHandler("/Home/Error"); } + //其他错误页面处理 + app.UseStatusCodePagesWithReExecute("/StatusCode/{0}"); //启用Session app.UseSession(); app.UseStaticFiles(); diff --git a/COMCMS.Web/Views/StatusCode/Index.cshtml b/COMCMS.Web/Views/StatusCode/Index.cshtml new file mode 100644 index 0000000..753af46 --- /dev/null +++ b/COMCMS.Web/Views/StatusCode/Index.cshtml @@ -0,0 +1,73 @@ +@model int +@{ + ViewData["Title"] = "Error"; + Layout = null; +} +@{ + var statusCode = Model; + var statusmessage = ""; + var tipmessage = "服务器好像出开了个小差..."; + switch (statusCode) + { + case 400: + statusmessage = "Bad request: The request cannot be fulfilled due to bad syntax"; + break; + case 403: + statusmessage = "Forbidden"; + break; + case 404: + statusmessage = "系统找不到本页面"; + tipmessage = "您所访问的页面好像被吃了..."; + break; + case 408: + statusmessage = "The server timed out waiting for the request"; + break; + case 500: + statusmessage = "Internal Server Error - server was unable to finish processing the request"; + break; + default: + statusmessage = "That's odd... Something we didn't expect happened"; + break; + } +} + + + + + + + + @(Model)错误 + + + + + + + + + +
+

@Model

+

@statusmessage

+
+ @(tipmessage) +
+ 当前页面:@ViewBag.url +
您可以返回主页看看 +
返回 +
+
+ + + + + + + + + + + + + \ No newline at end of file