Skip to content

Commit

Permalink
Refactor AccessDenied methods and clean up usings (Log entries create…
Browse files Browse the repository at this point in the history
…d from user input)
  • Loading branch information
KrzysztofPajak committed Oct 3, 2024
1 parent 7439944 commit a03bef8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/Web/Grand.Web.Admin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,16 @@ public async Task<IActionResult> GetStatesByCountryId([FromServices] ICountrySer
return Json(result);
}

public async Task<IActionResult> AccessDenied(string pageUrl)
public async Task<IActionResult> AccessDenied()
{
var currentCustomer = _workContext.CurrentCustomer;
if (currentCustomer == null || await _groupService.IsGuest(currentCustomer))
{
_logger.LogInformation("Access denied to anonymous request on {PageUrl}", pageUrl);
_logger.LogInformation("Access denied to anonymous request");
return View();
}

_logger.LogInformation("Access denied to user #{CurrentCustomerEmail} \'{CurrentCustomerEmail}\' on {PageUrl}",
currentCustomer.Email, currentCustomer.Email, pageUrl);
_logger.LogInformation("Access denied to user #{CurrentCustomerEmail} \'{CurrentCustomerEmail}\'", currentCustomer.Email, currentCustomer.Email);

return View();
}
Expand Down
4 changes: 1 addition & 3 deletions src/Web/Grand.Web.Common/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
using Grand.Web.Common.Events;
using Grand.Web.Common.Extensions;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Models;
using Grand.Web.Common.Page;
using MediatR;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
Expand Down Expand Up @@ -216,7 +214,7 @@ protected virtual async Task AddLocales<TLocalizedModelLocal>(ILanguageService l
/// <returns>Access denied view</returns>
protected IActionResult AccessDeniedView()
{
return RedirectToAction("AccessDenied", "Home", new { pageUrl = HttpContext.Request.GetEncodedPathAndQuery() });
return RedirectToAction("AccessDenied", "Home");
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions src/Web/Grand.Web.Vendor/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ public IActionResult Statistics()
return View();
}

public IActionResult AccessDenied(string pageUrl)
public IActionResult AccessDenied()
{
_logger.LogInformation("Access denied to user #{CurrentCustomerEmail} on {PageUrl}",
_workContext.CurrentCustomer.Email, pageUrl);
_logger.LogInformation("Access denied to user #{CurrentCustomerEmail}", _workContext.CurrentCustomer.Email);
return View();
}

Expand Down

0 comments on commit a03bef8

Please sign in to comment.