Advertisement
Kenedy-Hernique

Untitled

Aug 26th, 2021
243
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Microsoft.AspNetCore.Mvc.Filters;
  2. using System;
  3. using Grand.Infrastructure;
  4. using Grand.Business.Common.Interfaces.Directory;
  5.  
  6. using Grand.Business.Common.Services.Directory;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.AspNetCore.Routing;
  9.  
  10. namespace Grand.Web.Filters
  11. {
  12.     public class IsLoggedInFilterAttribute : Attribute, IActionFilter
  13.     {
  14.         #region Fields
  15.  
  16.         private IWorkContext _workContext;
  17.         private IGroupService _groupService;
  18.  
  19.         #endregion
  20.  
  21.         #region Constructors
  22.         public IsLoggedInFilterAttribute()
  23.         {
  24.  
  25.         }
  26.         #endregion
  27.  
  28.         public async void OnActionExecuting(ActionExecutingContext context)
  29.         {
  30.             _groupService = (IGroupService)context.HttpContext.RequestServices.GetService(typeof(IGroupService));
  31.             _workContext = (IWorkContext)context.HttpContext.RequestServices.GetService(typeof(IWorkContext));
  32.             if (!await _groupService.IsRegistered(_workContext.CurrentCustomer))
  33.             {
  34.                 context.Result = new RedirectToRouteResult(
  35.                     new RouteValueDictionary
  36.                     {
  37.                         { "controller", "Account" },
  38.                         { "action", "Login" }
  39.                     });
  40.             }
  41.         }
  42.         public void OnActionExecuted(ActionExecutedContext context)
  43.         {
  44.  
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement