using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;

namespace Knoks.Api.Filters
{
    [AttributeUsage(AttributeTargets.Method)]
    public class UserForbid : Attribute, IActionFilter
    {
        public void OnActionExecuted(ActionExecutedContext context)
        {
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            if (context.GetApiBaseController().ContextUserId.HasValue)
                context.Result = new ForbidResult();
        }
    }
}
