Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.AspNetCore.Mvc.Filters;
- using System;
- using Grand.Infrastructure;
- using Grand.Business.Common.Interfaces.Directory;
- using Grand.Business.Common.Services.Directory;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Routing;
- namespace Grand.Web.Filters
- {
- public class IsLoggedInFilterAttribute : Attribute, IActionFilter
- {
- #region Fields
- private IWorkContext _workContext;
- private IGroupService _groupService;
- #endregion
- #region Constructors
- public IsLoggedInFilterAttribute()
- {
- }
- #endregion
- public async void OnActionExecuting(ActionExecutingContext context)
- {
- _groupService = (IGroupService)context.HttpContext.RequestServices.GetService(typeof(IGroupService));
- _workContext = (IWorkContext)context.HttpContext.RequestServices.GetService(typeof(IWorkContext));
- if (!await _groupService.IsRegistered(_workContext.CurrentCustomer))
- {
- context.Result = new RedirectToRouteResult(
- new RouteValueDictionary
- {
- { "controller", "Account" },
- { "action", "Login" }
- });
- }
- }
- public void OnActionExecuted(ActionExecutedContext context)
- {
- }
- }
- }
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement