Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

PageController.cs - minor changes

supportc8d449750ce5
diff --git a/src/Web/Grand.Web/Controllers/PageController.cs b/src/Web/Grand.Web/Controllers/PageController.cs
index a97f3bf01..dbf90252a 100644
--- a/src/Web/Grand.Web/Controllers/PageController.cs
+++ b/src/Web/Grand.Web/Controllers/PageController.cs
@@ -3,6 +3,7 @@ using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Business.Core.Utilities.Common.Security;
using Grand.Web.Common.Filters;
using Grand.Web.Features.Models.Pages;
+using Grand.Web.Models.Pages;
using MediatR;
using Microsoft.AspNetCore.Mvc;
@@ -53,7 +54,8 @@ namespace Grand.Web.Controllers
var layoutViewPath = await _mediator.Send(new GetPageLayoutViewPath { LayoutId = model.PageLayoutId });
//display "edit" (manage) link
- if (await _permissionService.Authorize(StandardPermission.AccessAdminPanel) && await _permissionService.Authorize(StandardPermission.ManagePages))
+ if (await _permissionService.Authorize(StandardPermission.AccessAdminPanel) &&
+ await _permissionService.Authorize(StandardPermission.ManagePages))
DisplayEditLink(Url.Action("Edit", "Page", new { id = model.Id, area = "Admin" }));
return View(layoutViewPath, model);
@@ -74,9 +76,12 @@ namespace Grand.Web.Controllers
[DenySystemAccount]
[HttpPost]
- public virtual async Task<IActionResult> Authenticate(string id, string password)
+ public virtual async Task<IActionResult> Authenticate(AuthenticateModel model)
{
- if (string.IsNullOrEmpty(id))
+ if (!ModelState.IsValid)
+ return Json(new { Authenticated = false, Error = "Model is not valid" });
+
+ if (string.IsNullOrEmpty(model.Id))
return Json(new { Authenticated = false, Error = "Empty id" });
var authResult = false;
@@ -84,11 +89,11 @@ namespace Grand.Web.Controllers
var body = string.Empty;
var error = string.Empty;
- var page = await _mediator.Send(new GetPageBlock { PageId = id, Password = password });
+ var page = await _mediator.Send(new GetPageBlock { PageId = model.Id, Password = model.Password });
if (page is not { IsPasswordProtected: true })
return Json(new { Authenticated = authResult, Title = title, Body = body, Error = error });
- if (page.Password != null && page.Password.Equals(password))
+ if (page.Password != null && page.Password.Equals(model.Password))
{
authResult = true;
title = page.Title;
@@ -98,9 +103,10 @@ namespace Grand.Web.Controllers
{
error = _translationService.GetResource("Page.WrongPassword");
}
+
return Json(new { Authenticated = authResult, Title = title, Body = body, Error = error });
}
#endregion
}
-}
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Pages/AuthenticateModel.cs b/src/Web/Grand.Web/Models/Pages/AuthenticateModel.cs
new file mode 100644
index 000000000..fdc7f8c69
--- /dev/null
+++ b/src/Web/Grand.Web/Models/Pages/AuthenticateModel.cs
@@ -0,0 +1,7 @@
+namespace Grand.Web.Models.Pages;
+
+public class AuthenticateModel
+{
+ public string Id { get; set; }
+ public string Password { get; set; }
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Views/Page/PageDetails.cshtml b/src/Web/Grand.Web/Views/Page/PageDetails.cshtml
index e83151721..806a82d18 100644
--- a/src/Web/Grand.Web/Views/Page/PageDetails.cshtml
+++ b/src/Web/Grand.Web/Views/Page/PageDetails.cshtml
@@ -36,8 +36,6 @@
}
<script asp-location="Footer" asp-order="300">
- document.addEventListener("DOMContentLoaded", function () {
-
function passwordProtect() {
var postData = {
id: document.getElementById("@Html.IdFor(model => model.Id)").value,
@@ -70,19 +68,16 @@
})
}
- document.getElementById('ph-page').style.display = "none";
-
- document.getElementById("passwordPage").onkeypress = function (e) {
- var key = e.charCode || e.keyCode || 0;
- if (key == 13) {
- passwordProtect()
- e.preventDefault();
+ document.getElementById('ph-page').style.display = "none";
+ document.addEventListener("keydown", (e) => {
+ if (e.key == "Enter"){
+ passwordProtect();
}
- }
- });
+ });
+
</script>
<div class="page page-password" id="ph-password">
- <form id="passwordPage" asp-route="PageAuthenticate" method="post">
+ <form id="passwordPage" asp-route="PageAuthenticate" method="post" onsubmit="return false">
<input asp-for="Id" type="hidden" />
<div class="enter-password-title">
@Loc["Page.EnterPassword"]