diff --git a/CMSAdmin/CMSAdminCore.csproj b/CMSAdmin/CMSAdminCore.csproj index 7a31420..bbeb8b1 100644 --- a/CMSAdmin/CMSAdminCore.csproj +++ b/CMSAdmin/CMSAdminCore.csproj @@ -14,8 +14,10 @@ Carrotware Carrotware $([System.DateTime]::Now.Year) - Carrot Cake CMS, built @ $([System.DateTime]::UtcNow.ToString("yyMMdd")) $([System.DateTime]::UtcNow.ToString("HH:mm")) - Carrot Cake CMS, debug built @ $([System.DateTime]::UtcNow.ToString("yyMMdd")) $([System.DateTime]::UtcNow.ToString("HH:mm")) DEBUG + Carrot Cake CMS + $([System.DateTime]::UtcNow.ToString("yyyy.MM.dd")) $([System.DateTime]::UtcNow.ToString("HH:mm")) UTC + $(AppName), built @ $(BuildDateTime) + $(AppName), debug built @ $(BuildDateTime) true 8.1 $([System.DateTime]::op_Subtraction($([System.DateTime]::get_Now().get_Date()),$([System.DateTime]::new(2000,1,1))).get_TotalDays()) diff --git a/CMSAdmin/Controllers/CmsAdminApiController.cs b/CMSAdmin/Controllers/CmsAdminApiController.cs index e3529e8..4ee2e66 100644 --- a/CMSAdmin/Controllers/CmsAdminApiController.cs +++ b/CMSAdmin/Controllers/CmsAdminApiController.cs @@ -431,10 +431,10 @@ public static class ServiceResponse { public string ValidateUniqueCategory(string TheSlug, string ItemID) { try { Guid CurrentItemGuid = new Guid(ItemID); - TheSlug = CMSConfigHelper.DecodeBase64(TheSlug); - TheSlug = ContentPageHelper.ScrubSlug(TheSlug); + var theSlug = CMSConfigHelper.DecodeBase64(TheSlug); + theSlug = ContentPageHelper.ScrubSlug(theSlug); - int iCount = ContentCategory.GetSimilar(SiteData.CurrentSite.SiteID, CurrentItemGuid, TheSlug); + int iCount = ContentCategory.GetSimilar(SiteData.CurrentSite.SiteID, CurrentItemGuid, theSlug); if (iCount < 1) { return JsonSerializer.Serialize(ServiceResponse.OK); @@ -453,10 +453,10 @@ public static class ServiceResponse { public string ValidateUniqueTag(string TheSlug, string ItemID) { try { Guid CurrentItemGuid = new Guid(ItemID); - TheSlug = CMSConfigHelper.DecodeBase64(TheSlug); - TheSlug = ContentPageHelper.ScrubSlug(TheSlug); + var theSlug = CMSConfigHelper.DecodeBase64(TheSlug); + theSlug = ContentPageHelper.ScrubSlug(theSlug); - int iCount = ContentTag.GetSimilar(SiteData.CurrentSite.SiteID, CurrentItemGuid, TheSlug); + int iCount = ContentTag.GetSimilar(SiteData.CurrentSite.SiteID, CurrentItemGuid, theSlug); if (iCount < 1) { return JsonSerializer.Serialize(ServiceResponse.OK); @@ -472,18 +472,18 @@ public static class ServiceResponse { } [HttpPost] - public string RecordSnippetHeartbeat(string ItemID) { + public string RecordSnippetHeartbeat([FromBody] ApiModel model) { try { - Guid CurrentItemGuid = new Guid(ItemID); + Guid CurrentItemGuid = new Guid(model.ItemID); ContentSnippet item = GetSnippet(CurrentItemGuid); - bool bRet = false; + bool ret = false; if (item != null && !item.IsLocked) { - bRet = item.RecordSnippetLock(SecurityData.CurrentUserGuid); + ret = item.RecordSnippetLock(SecurityData.CurrentUserGuid); } - if (bRet) { + if (ret) { return JsonSerializer.Serialize(SiteData.CurrentSite.Now.ToString()); } else { return JsonSerializer.Serialize(Convert.ToDateTime("12/31/1899").ToString()); @@ -497,9 +497,9 @@ public static class ServiceResponse { } [HttpPost] - public string CancelSnippetEditing(string ItemID) { + public string CancelSnippetEditing([FromBody] ApiModel model) { try { - Guid currentItemGuid = new Guid(ItemID); + Guid currentItemGuid = new Guid(model.ItemID); ContentSnippet item = GetSnippet(currentItemGuid); if (item != null && !item.IsLocked) { @@ -525,12 +525,12 @@ public static class ServiceResponse { return item; } - [HttpPost] + [HttpGet] public string ValidateUniqueSnippet(string TheSlug, string ItemID) { try { Guid currentItemGuid = new Guid(ItemID); - TheSlug = CMSConfigHelper.DecodeBase64(TheSlug); - TheSlug = ContentPageHelper.ScrubSlug(TheSlug); + var theSlug = CMSConfigHelper.DecodeBase64(TheSlug); + theSlug = ContentPageHelper.ScrubSlug(theSlug); ContentSnippet item = GetSnippet(currentItemGuid); @@ -538,7 +538,7 @@ public static class ServiceResponse { currentItemGuid = item.Root_ContentSnippetID; } - int count = ContentSnippet.GetSimilar(SiteData.CurrentSite.SiteID, currentItemGuid, TheSlug); + int count = ContentSnippet.GetSimilar(SiteData.CurrentSite.SiteID, currentItemGuid, theSlug); if (count < 1) { return JsonSerializer.Serialize(ServiceResponse.OK); @@ -670,34 +670,34 @@ public static class ServiceResponse { public string GenerateCategoryTagSlug(string TheSlug, string ItemID, string Mode) { try { Guid currentItemGuid = new Guid(ItemID); - TheSlug = CMSConfigHelper.DecodeBase64(TheSlug); - TheSlug = ContentPageHelper.ScrubSlug(TheSlug).ToLowerInvariant(); + var theSlug = CMSConfigHelper.DecodeBase64(TheSlug); + theSlug = ContentPageHelper.ScrubSlug(theSlug).ToLowerInvariant(); var matches = 0; var count = 0; var siteid = SiteData.CurrentSite.SiteID; if (Mode.ToLowerInvariant() == "category") { - matches = ContentCategory.GetSimilar(siteid, currentItemGuid, TheSlug); + matches = ContentCategory.GetSimilar(siteid, currentItemGuid, theSlug); if (matches > 0) { count = 1; while (count < 2000 && matches > 0) { - TheSlug = string.Format("{0}-{1}", TheSlug, count); - matches = ContentCategory.GetSimilar(siteid, currentItemGuid, TheSlug); + theSlug = string.Format("{0}-{1}", theSlug, count); + matches = ContentCategory.GetSimilar(siteid, currentItemGuid, theSlug); } } } if (Mode.ToLowerInvariant() == "tag") { - matches = ContentTag.GetSimilar(siteid, currentItemGuid, TheSlug); + matches = ContentTag.GetSimilar(siteid, currentItemGuid, theSlug); if (matches > 0) { count = 1; while (count < 2000 && matches > 0) { - TheSlug = string.Format("{0}-{1}", TheSlug, count); - matches = ContentTag.GetSimilar(siteid, currentItemGuid, TheSlug); + theSlug = string.Format("{0}-{1}", theSlug, count); + matches = ContentTag.GetSimilar(siteid, currentItemGuid, theSlug); } } } - return JsonSerializer.Serialize(ContentPageHelper.ScrubSlug(TheSlug)); + return JsonSerializer.Serialize(ContentPageHelper.ScrubSlug(theSlug)); } catch (Exception ex) { _logger.LogError(ex, "GenerateCategoryTagSlug"); SiteData.WriteDebugException("webservice", ex); @@ -707,11 +707,12 @@ public static class ServiceResponse { } [HttpPost] - public string GenerateSnippetSlug(string TheSlug) { + public string GenerateSnippetSlug([FromBody] ApiModel model) { try { - TheSlug = CMSConfigHelper.DecodeBase64(TheSlug).ToLowerInvariant().Trim(); + var theSlug = model.TheSlug; + theSlug = CMSConfigHelper.DecodeBase64(theSlug).ToLowerInvariant().Trim(); - return JsonSerializer.Serialize(ContentPageHelper.ScrubSlug(TheSlug)); + return JsonSerializer.Serialize(ContentPageHelper.ScrubSlug(theSlug)); } catch (Exception ex) { _logger.LogError(ex, "GenerateSnippetSlug"); SiteData.WriteDebugException("webservice", ex); diff --git a/CMSAdmin/Controllers/CmsAdminController.cs b/CMSAdmin/Controllers/CmsAdminController.cs index c423ec6..0fe8296 100644 --- a/CMSAdmin/Controllers/CmsAdminController.cs +++ b/CMSAdmin/Controllers/CmsAdminController.cs @@ -100,7 +100,7 @@ public class CmsAdminController : Controller { [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult LogOff() { - SignOut(); + ClearUserSession(); SessionContext.CleanExpiredSession(); @@ -587,7 +587,7 @@ public class CmsAdminController : Controller { [AllowAnonymous] public ActionResult DatabaseSetup(string signout) { if (!string.IsNullOrEmpty(signout)) { - SignOut(); + ClearUserSession(); Response.Redirect(SiteFilename.DatabaseSetupURL); } @@ -603,7 +603,7 @@ public class CmsAdminController : Controller { RedirectIfUsersExist(); if (SecurityData.IsAuthenticated) { - SignOut(); + ClearUserSession(); return RedirectToAction(SiteActions.CreateFirstAdmin, new { @signout = true }); } @@ -620,7 +620,7 @@ public class CmsAdminController : Controller { RedirectIfUsersExist(); if (ModelState.IsValid) { - SignOut(); + ClearUserSession(); SecurityData sd = new SecurityData(); IdentityUser user = new IdentityUser { UserName = model.UserName, Email = model.Email }; @@ -838,7 +838,8 @@ public class CmsAdminController : Controller { if (id.HasValue) { model = ContentCategory.Get(id.Value); - } else { + } + if (model == null) { model = new ContentCategory(); model.ContentCategoryID = Guid.Empty; } @@ -850,6 +851,7 @@ public class CmsAdminController : Controller { [ValidateAntiForgeryToken] public ActionResult CategoryAddEdit(ContentCategory model) { Helper.ForceValidation(ModelState, model); + model.ClearOptionalItems(ModelState); if (ModelState.IsValid) { ContentCategory item = ContentCategory.Get(model.ContentCategoryID); @@ -877,6 +879,7 @@ public class CmsAdminController : Controller { [HttpPost] [ValidateAntiForgeryToken] public ActionResult CategoryDelete(ContentCategory model) { + model.ClearOptionalItems(ModelState); ContentCategory item = ContentCategory.Get(model.ContentCategoryID); item.Delete(); @@ -889,7 +892,8 @@ public class CmsAdminController : Controller { if (id.HasValue) { model = ContentTag.Get(id.Value); - } else { + } + if (model == null) { model = new ContentTag(); model.ContentTagID = Guid.Empty; } @@ -901,6 +905,7 @@ public class CmsAdminController : Controller { [ValidateAntiForgeryToken] public ActionResult TagAddEdit(ContentTag model) { Helper.ForceValidation(ModelState, model); + model.ClearOptionalItems(ModelState); if (ModelState.IsValid) { ContentTag item = ContentTag.Get(model.ContentTagID); @@ -928,6 +933,7 @@ public class CmsAdminController : Controller { [HttpPost] [ValidateAntiForgeryToken] public ActionResult TagDelete(ContentTag model) { + model.ClearOptionalItems(ModelState); ContentTag item = ContentTag.Get(model.ContentTagID); item.Delete(); @@ -1161,7 +1167,7 @@ public class CmsAdminController : Controller { } [HttpGet] - public ActionResult PageAddEdit(Guid? id, Guid? versionid, Guid? importid, string mode) { + public ActionResult PageAddEdit(Guid? id, Guid? versionid, Guid? importid, string? mode) { ContentPageModel model = new ContentPageModel(); ContentPage pageContents = model.GetPage(id, versionid, importid, mode); ViewBag.ContentEditMode = SiteData.EditMode(model.Mode); @@ -1271,7 +1277,7 @@ public class CmsAdminController : Controller { } [HttpGet] - public ActionResult BlogPostAddEdit(Guid? id, Guid? versionid, Guid? importid, string mode) { + public ActionResult BlogPostAddEdit(Guid? id, Guid? versionid, Guid? importid, string? mode) { ContentPageModel model = new ContentPageModel(); ContentPage pageContents = model.GetPost(id, versionid, importid, mode); ViewBag.ContentEditMode = SiteData.EditMode(model.Mode); @@ -1284,7 +1290,7 @@ public class CmsAdminController : Controller { } [HttpGet] - public ActionResult ContentSnippetAddEdit(Guid? id, Guid? versionid, string mode) { + public ActionResult ContentSnippetAddEdit(Guid? id, Guid? versionid, string? mode) { ViewBag.ContentEditMode = SiteData.EditMode(mode); ContentSnippet model = null; @@ -1308,7 +1314,7 @@ public class CmsAdminController : Controller { [HttpPost] [ValidateAntiForgeryToken] - public ActionResult ContentSnippetAddEdit(ContentSnippet model, string mode) { + public ActionResult ContentSnippetAddEdit(ContentSnippet model, string? mode) { ViewBag.ContentEditMode = SiteData.EditMode(mode); Helper.ForceValidation(ModelState, model); @@ -1393,10 +1399,10 @@ public class CmsAdminController : Controller { public ActionResult ControlPropertiesEdit(Guid id, Guid pageid) { cmsHelper.OverrideKey(pageid); - Widget w = (from aw in cmsHelper.cmsAdminWidget - where aw.Root_WidgetID == id - orderby aw.WidgetOrder, aw.EditDate - select aw).FirstOrDefault(); + var w = (from aw in cmsHelper.cmsAdminWidget + where aw.Root_WidgetID == id + orderby aw.WidgetOrder, aw.EditDate + select aw).FirstOrDefault(); List lstProps = ObjectProperty.GetWidgetProperties(w); @@ -1412,10 +1418,10 @@ public class CmsAdminController : Controller { public ActionResult ControlPropertiesEdit(WidgetProperties model) { cmsHelper.OverrideKey(model.Widget.Root_ContentID); - Widget w = (from aw in cmsHelper.cmsAdminWidget - where aw.Root_WidgetID == model.Widget.Root_WidgetID - orderby aw.WidgetOrder, aw.EditDate - select aw).FirstOrDefault(); + var w = (from aw in cmsHelper.cmsAdminWidget + where aw.Root_WidgetID == model.Widget.Root_WidgetID + orderby aw.WidgetOrder, aw.EditDate + select aw).FirstOrDefault(); var props = new List(); @@ -1659,7 +1665,7 @@ public class CmsAdminController : Controller { } [HttpGet] - public ActionResult ContentEdit(Guid id, Guid? widgetid, string field, string mode) { + public ActionResult ContentEdit(Guid id, Guid? widgetid, string field, string? mode) { ContentSingleModel model = new ContentSingleModel(); model.Mode = mode; model.Field = field; @@ -1669,9 +1675,9 @@ public class CmsAdminController : Controller { cmsHelper.OverrideKey(model.PageId); if (widgetid.HasValue) { - Widget pageWidget = (from w in cmsHelper.cmsAdminWidget - where w.Root_WidgetID == widgetid.Value - select w).FirstOrDefault(); + var pageWidget = (from w in cmsHelper.cmsAdminWidget + where w.Root_WidgetID == widgetid.Value + select w).FirstOrDefault(); model.PageText = pageWidget.ControlProperties; } else { @@ -1707,9 +1713,9 @@ public class CmsAdminController : Controller { if (model.WidgetId.HasValue && model.WidgetId.Value != Guid.Empty) { List lstWidgets = cmsHelper.cmsAdminWidget; - Widget pageWidget = (from w in lstWidgets - where w.Root_WidgetID == model.WidgetId.Value - select w).FirstOrDefault(); + var pageWidget = (from w in lstWidgets + where w.Root_WidgetID == model.WidgetId.Value + select w).FirstOrDefault(); pageWidget.ControlProperties = model.PageText; pageWidget.WidgetDataID = Guid.NewGuid(); @@ -2916,7 +2922,7 @@ where aw.PlaceholderName.ToLowerInvariant() == model.PlaceholderName.ToLowerInva return View(); } - protected void SignOut() { + protected void ClearUserSession() { securityHelper.SignInManager.SignOutAsync(); this.HttpContext.Session.Clear(); } diff --git a/CMSAdmin/Views/CmsAdmin/ContentSnippetAddEdit.cshtml b/CMSAdmin/Views/CmsAdmin/ContentSnippetAddEdit.cshtml index 87fadbd..e55b0d2 100644 --- a/CMSAdmin/Views/CmsAdmin/ContentSnippetAddEdit.cshtml +++ b/CMSAdmin/Views/CmsAdmin/ContentSnippetAddEdit.cshtml @@ -12,7 +12,7 @@ bool bLocked = Model.IsLocked && Model.Heartbeat_UserId.HasValue; } -@section scripts{ +@section scripts {