Exemplo n.º 1
0
 public async Task <List <Menu> > GetMenu(int empresaId)
 {
     try
     {
         return(await _menuAppService.GetAll(menu => menu.Ativo == true && menu.EmpresaId == empresaId));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 2
0
        //授权处理
        protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, PolicyRequirement requirement)
        {
            //Todo:获取角色、Url 对应关系
            List <Menu> list = await _menuApp.GetAll();


            var httpContext = (context.Resource as AuthorizationFilterContext).HttpContext;

            //获取授权方式
            var defaultAuthenticate = await Schemes.GetDefaultAuthenticateSchemeAsync();

            if (defaultAuthenticate != null)
            {
                //验证签发的用户信息
                var result = await httpContext.AuthenticateAsync(defaultAuthenticate.Name);

                if (result.Succeeded)
                {
                    //判断是否为已停用的 Token
                    if (!await _jwtApp.IsCurrentActiveTokenAsync())
                    {
                        context.Fail();
                        return;
                    }

                    httpContext.User = result.Principal;

                    //判断角色与 Url 是否对应
                    //
                    var url  = httpContext.Request.Path.Value;
                    var role = httpContext.User.Claims.Where(c => c.Type == ClaimTypes.Role).Select(x => x.Value).ToList();
                    var menu = list.Where(x => url.Contains(x.Url) && role.Contains(x.RoleName)).FirstOrDefault();

                    if (menu == null)
                    {
                        context.Fail();
                        return;
                    }


                    /*  var menu = list.Where(x => x.Role.Equals(role) && x.Url.ToLower().Equals(url)).FirstOrDefault()*/;



                    //判断是否过期
                    if (DateTime.Parse(httpContext.User.Claims.SingleOrDefault(s => s.Type == ClaimTypes.Expiration).Value) >= DateTime.UtcNow)
                    {
                        context.Succeed(requirement);
                    }
                    else
                    {
                        context.Fail();
                    }
                    return;
                }
            }
            context.Fail();
        }
Exemplo n.º 3
0
        public ItemsLinkContainer <MenuViewModel> Get()
        {
            var menus = _menuAppService.GetAll().ToList();

            menus.ForEach(x => x.AddRangeLink(_menuEnricher.CreateLinks(Method.Get, x)));
            var result = new ItemsLinkContainer <MenuViewModel>()
            {
                Items = menus
            };

            result.AddRangeLink(_menuEnricher.CreateLinks(Method.GetAll));
            return(result);
        }
Exemplo n.º 4
0
        public async Task <JsonResult> GetAsync([FromQuery] MenuQueryDto condition)
        {
            if (condition.RoleName != null || condition.Url != null)
            {
                var list = _service.Search(condition);
                return(new JsonResult(new
                {
                    code = 20000,
                    list
                }));
            }
            var items = await _service.GetAll();

            return(new JsonResult(new
            {
                code = 20000,
                items
            }));
        }
 public IEnumerable <Menu> Get()
 {
     return(_appService.GetAll());
 }
Exemplo n.º 6
0
 public IActionResult Index()
 {
     Logger.Error("测试。");
     _service.GetAll();
     return(View());
 }