Ejemplo n.º 1
0
        public ActionResult selectRoleForUser(string userid, string roleid)
        {
            string     _Code = "1", _msg = "分配角色成功";
            SystemRole role = _SystemRoleService.GetKey(roleid);

            try
            {
                UserInfo user = _UserInfoService.GetKey(userid);
                if (role == null)
                {
                    _Code = "-1"; _msg = "角色不存在" + userid + roleid;
                }
                else if (user == null)
                {
                    _Code = "-2"; _msg = "用户不存在";
                }
                else
                {
                    user.Role = role;
                    _UserInfoService.Edit(user);
                    _UserInfoService.Save();
                }
            }
            catch (Exception error)
            {
                _Code = "-2"; _msg = "异常:" + error.Message;
            }

            return(Json(new { Code = _Code, msg = _msg }, JsonRequestBehavior.AllowGet));
        }
        //权限判断业务逻辑
        protected virtual bool AuthorizeCore(ActionExecutingContext filterContext, bool isViewPage)
        {
            if (filterContext.HttpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                return(false);//判定用户是否登录
            }
            //获取当前用户信息
            UserInfo        user             = new UserInfo();
            UserInfoService _UserInfoService = new UserInfoService();

            user = _UserInfoService.GetKey((filterContext.HttpContext.User.Identity as FormsIdentity).Ticket.UserData.Split("|".ToCharArray())[0]);
            //var area = filterContext.RouteData.DataTokens["area"];
            //var controllerName = filterContext.RouteData.Values["controller"].ToString();
            //var actionName = filterContext.RouteData.Values["action"].ToString();
            if (isViewPage)//如果当前Action请求为具体的功能页并且不是MasterPage页
            {
                Predicate <SystemMenu> match = delegate(SystemMenu menu)
                {
                    if ((menu.Code.ToLower()) == area + "." + Controller + "." + Action)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                };
                SystemMenu has_menu = user.Role.Menu.Find(match);
                if (has_menu == null)
                {
                    return(false);
                }

                //if (user.Role.Menu(m => m.ControllerName == controllerName && m.ActionName == actionName) == 0)
                //    return false;
            }
            else
            {
                //var actions = ContainerFactory.GetContainer().Resolve<IAuthorityFacade>().GetAllActionPermission();//所有被维护的Action权限
                //if (actions.Count(a => a.ControllerName == controllerName && a.ActionName == actionName) != 0)//如果当前Action属于被维护的Action权限
                //{
                //    if (user.ActionPermission.Count(a => a.ControllerName == controllerName && a.ActionName == actionName) == 0)
                //        return false;
                //}
            }
            return(true);
        }
        //权限判断业务逻辑
        protected virtual bool AuthorizeCore(ActionExecutingContext filterContext, bool isViewPage)
        {
            if (filterContext.HttpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                return false;//判定用户是否登录
            }
            //获取当前用户信息
            UserInfo user = new UserInfo();
            UserInfoService _UserInfoService = new UserInfoService();
            user = _UserInfoService.GetKey((filterContext.HttpContext.User.Identity as FormsIdentity).Ticket.UserData.Split("|".ToCharArray())[0]);
            //var area = filterContext.RouteData.DataTokens["area"];
            //var controllerName = filterContext.RouteData.Values["controller"].ToString();
            //var actionName = filterContext.RouteData.Values["action"].ToString();
            if (isViewPage)//如果当前Action请求为具体的功能页并且不是MasterPage页
            {
                Predicate<SystemMenu> match = delegate(SystemMenu menu)
                {
                    if ((menu.Code.ToLower()) == area + "." + Controller + "." + Action)
                        return true;
                    else
                        return false;
                };
                SystemMenu has_menu = user.Role.Menu.Find(match);
                if (has_menu == null)
                    return false;

                //if (user.Role.Menu(m => m.ControllerName == controllerName && m.ActionName == actionName) == 0)
                //    return false;
            }
            else
            {
                //var actions = ContainerFactory.GetContainer().Resolve<IAuthorityFacade>().GetAllActionPermission();//所有被维护的Action权限
                //if (actions.Count(a => a.ControllerName == controllerName && a.ActionName == actionName) != 0)//如果当前Action属于被维护的Action权限
                //{
                //    if (user.ActionPermission.Count(a => a.ControllerName == controllerName && a.ActionName == actionName) == 0)
                //        return false;
                //}
            }
            return true;
        }
Ejemplo n.º 4
0
        public ActionResult Index()
        {
            //Reqest();

            //XElement root = XElement.Load(Server.MapPath("~/") + "App_Data\\TreeMenu.xml");
            ViewBag.SigninName  = SigninName;
            ViewBag.SigninId    = SigninId;
            ViewBag.SigninEmail = SigninEmail;
            //1获取当前所有权限菜单
            ViewBag.ActionMenu = "";
            if (SigninId != "0")
            {
                //如果不是超级管理员,获取当前用户
                UserInfo user = _UserInfoService.GetKey(SigninId);
                ViewBag.ActionMenu = string.Join(";", user.Role.Menu.Select(m => m.Code).ToArray());
            }
            Session.Add("ActionMenu", ViewBag.ActionMenu);


            //long total = 0;
            //QueryActionPlist("s", 1, 20, out total);
            return(View());
        }