Esempio n. 1
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            bool isAuthorized = context.HttpContext.User.Identity.IsAuthenticated;

            using (var service = serviceFunc())
            {
                string userId = identity.GetEmail();

                if (!isAuthorized)
                {
                    context.Result = new UnauthorizedResult();
                    return;
                }

                var results = await GetResult(screens, actions);

                if (results.Any(x => x >= level))
                {
                    await next();
                }
                else
                {
                    context.Result = new JsonResult(results)
                    {
                        StatusCode = 403,
                        Value      = new
                        {
                            Errors = new Dictionary <string, string>
                            {
                                ["Error"] = "Access Denied. Please contact your administrator."
                            }
                        }
                    };

                    return;
                }
            }
        }
Esempio n. 2
0
        public Company Add(CompanyModel companyModel)
        {
            var email = identity.GetEmail();

            var company = mapper.Map <Company>(companyModel,
                                               opts => opts.Items.Add("EmailAddress",
                                                                      new RuleStatement <string>(
                                                                          () => email.IsNotNullOrWhiteSpace(),
                                                                          new StopWithFuncRule <string>(() => email),
                                                                          new StopWithFuncRule <string>(() => "system")
                                                                          )));

            return(Add(company));
        }