Beispiel #1
0
        /// <summary>不在菜单中显示
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool CloseMenu(int id)
        {
            int result = PluginDao.ShowMenu(id, 0); if (result > 0)

            {
                HuberPluginHandle.setShowMenu(id, 0);
            }
            return(result > 0);
        }
Beispiel #2
0
        /// <summary>停用插件
        /// </summary>
        /// <param name="id"></param>
        public bool DisablePlugin(int id)
        {
            int result = PluginDao.SetPlugin(id, 0);

            if (result > 0)
            {
                PluginEntity pluginEntity = PluginDao.GetPlugin(id);
                if (pluginEntity != null)
                {
                    HuberPluginHandle.UnLoadPlugin(pluginEntity);
                }
            }
            return(result > 0);
        }
Beispiel #3
0
        /// <summary>验证登录
        /// </summary>
        /// <returns>2 具有访问权限 1 没有权限  0 未登录</returns>
        public int chekLogin(ref string uid, bool liwai, List <RightEntity> userRights)
        {
            int    result = 0;
            string sign   = CookieFunc.ReadCookie(CoSignKey);

            if (sign != null && sign != string.Empty)
            {
                uid = string.Empty;
                string   pwd = string.Empty;
                DateTime dt  = DateTime.Now;
                if (design(sign, ref uid, ref pwd, ref dt))
                {
                    if (dt.AddDays(15) > DateTime.Now)//令牌未过期
                    {
                        int signState = new LoginDal().exsitLoginSign(uid, sign, IsOnlyOne);
                        if (signState == 1)
                        {
                            result = 1;
                        }
                        else if (signState == -1)
                        {
                            if (1 == new UserDal().login(uid, pwd))
                            {
                                result = 1;
                            }
                        }
                        if (result > 0)
                        {
                            if (!liwai)
                            {
                                #region 获取当前页面的权限
                                UrlPathEntity      urlEntity = null;
                                List <RightEntity> rlist     = null;
                                if (HttpContext.Current.Request.RawUrl.StartsWith("/Plugins/"))
                                {
                                    urlEntity = HuberPluginHandle.getUrlPathEntity(HttpContext.Current.Request.RawUrl.Substring(8), true);
                                    rlist     = new RightBll().UserGetRights("/" + urlEntity.pluginname + "/" + urlEntity.controller + "/" + urlEntity.action);
                                }
                                else
                                {
                                    urlEntity = HuberPluginHandle.getUrlPathEntity(HttpContext.Current.Request.RawUrl, false);
                                    rlist     = new RightBll().UserGetRights("/" + urlEntity.controller + "/" + urlEntity.action);
                                }
                                UserEntity CurUer = new UserDal().GetUser(uid);
                                if (CurUer != null)
                                {
                                    if (rlist.Count > 0)
                                    {
                                        List <RightEntity> urights      = new List <RightEntity>();
                                        string             rightCompara = ",{0},";

                                        if (CurUer.Uid == SuperAdminID)//如果是超级管理员,不需要对权限筛选
                                        {
                                            urights = rlist;
                                        }
                                        else
                                        {
                                            List <RoleEntity> uRoles = new RoleBll().GetRoles(CurUer.RolesIds);
                                            if (uRoles != null && uRoles.Count > 0)
                                            {
                                                foreach (RightEntity right in rlist)
                                                {
                                                    foreach (RoleEntity role in uRoles)
                                                    {
                                                        if (role.RightIds.IndexOf(string.Format(rightCompara, right.Id)) > -1)
                                                        {
                                                            urights.Add(right);
                                                        }
                                                    }
                                                }
                                            }
                                        }


                                        userRights = urights;
                                        result     = 2;
                                    }
                                    else
                                    {
                                        if (CurUer.Uid == SuperAdminID)//如果是超级管理员,不需要对权限筛选
                                        {
                                            result = 2;
                                        }
                                    }
                                }



                                #endregion
                            }
                            else
                            {
                                result = 2;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #4
0
        // GET: /Home/

        public ActionResult Index()
        {
            UserEntity user = new UserBll().getCurUser();

            ViewBag.User = user;
            #region 菜单呈现
            List <string>     urights = new List <string>();
            List <MenuEntity> menus   = new List <MenuEntity>();
            if (user != null)
            {
                IEnumerable <PluginEntity> pluginEntities = HuberPluginHandle.getEntityForMenu();
                if (pluginEntities.Any())
                {
                    #region 用户的权限
                    List <RoleEntity> uroles     = new RoleBll().GetRoles(user.RolesIds);
                    string[]          rightRange = null;
                    string[]          splitchar  = new string[] { "," };
                    if (uroles != null)
                    {
                        foreach (RoleEntity role in uroles)
                        {
                            rightRange = role.RightIds.Split(splitchar, StringSplitOptions.RemoveEmptyEntries);
                            if (rightRange != null)
                            {
                                urights.AddRange(rightRange);
                            }
                        }
                    }
                    #endregion
                    List <RightEntity> rightEntities = new RightBll().GetAllMenu(urights, user.Uid == UserBll.SuperAdminID);
                    foreach (PluginEntity pluginEntity in pluginEntities)
                    {
                        RightEntity rightEntity = rightEntities.SingleOrDefault(m => m.Category == pluginEntity.Id && m.ParentId == 0);
                        if (rightEntity == null)
                        {
                            continue;
                        }
                        MenuEntity menuEntity = GetMenu(rightEntity, pluginEntity);
                        menus.Add(menuEntity);
                    }
                }
                #region 添加系统菜单
                if (user.Uid == UserBll.SuperAdminID)
                {
                    MenuEntity CoreMenu = new MenuEntity(-1, "系统管理", string.Empty, true, "fa fa-cog");
                    CoreMenu.Children.Add(new MenuEntity(-1, "用户管理", "/user/index", true));
                    CoreMenu.Children.Add(new MenuEntity(-1, "权限管理", "/right/index", true));
                    CoreMenu.Children.Add(new MenuEntity(-1, "角色管理", "/role/index", true));
                    CoreMenu.Children.Add(new MenuEntity(-1, "模块管理", "/module/index", true));
                    menus.Add(CoreMenu);
                    //menus.Add(CoreMenu);
                    //menus.Add(CoreMenu);
                    //menus.Add(CoreMenu);
                    //menus.Add(CoreMenu);
                }
                #endregion
            }
            #endregion



            ViewBag.Menus = menus;
            return(View());
        }
Beispiel #5
0
        // 请求拦截
        private void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            HttpResponse    respond     = application.Response;
            HttpRequest     request     = application.Request;
            string          url         = request.Url.AbsolutePath.ToString();

            //如果请求以“/plugins/”开头,表面我们需要对该请求做拦截处理了。
            if (url.ToLower().StartsWith("/plugins/"))
            {
                string action = url.Substring(url.LastIndexOf("/") + 1);
                //如果是非静态文件,即是action
                if (action.IndexOf(".") < 0)
                {
                    #region 匹配controller和action

                    var urlEntity = HuberPluginHandle.getUrlPathEntity(url.Substring(8), true);
                    #endregion
                    if (urlEntity != null && urlEntity.controller != null)
                    {
                        #region 获取路径中的插件名称等信息

                        #endregion
                        SandBoxDynamicLoader sandBox = HuberPluginHandle.getSandBox(urlEntity.pluginname, urlEntity.pluginversion);

                        if (sandBox != null)
                        {
                            List <RightEntity> userRight = new List <RightEntity>();
                            string             uid       = string.Empty;
                            int login = new UserBll().chekLogin(ref uid, false, userRight);
                            if (login == 2)//验证用户是否具有访问的权限
                            {
                                RefRequestEntity paras = new RefRequestEntity();
                                paras.PageRights = userRight;
                                paras.UserID     = uid;
                                #region 获取http参数
                                RequestHandle.FillCorRefEntity(paras, request);
                                #endregion
                                //sandBox.InvokeMothod(urlEntity.controller, "InitChannel", paras)
                                var result = sandBox.InvokeMothod(urlEntity.controller, urlEntity.action, paras);
                                RequestHandle.ResposeResult(respond, result);
                            }
                            else if (login == 1)
                            {
                                RequestHandle.ResponseNoRight(request, respond);
                            }
                            else
                            {
                                RequestHandle.ResponseNoLogin(request, respond);
                            }
                        }
                    }
                    else
                    {
                        RequestHandle.ResponseNotfound(request, respond);;
                    }

                    respond.End();
                }
            }
            else
            {
                if (!url.ToLower().Equals("/user/login"))
                {
                    string action = url.Substring(url.LastIndexOf("/") + 1);
                    if (action.IndexOf(".") < 0)
                    {
                        List <RightEntity> userRight = new List <RightEntity>();
                        string             uid       = string.Empty;
                        int login = new UserBll().chekLogin(ref uid, false, userRight);
                        if (login == 2)//验证用户是否具有访问的权限
                        {
                        }
                        else if (login == 1)
                        {
                            RequestHandle.ResponseNoRight(request, respond);
                        }
                        else
                        {
                            RequestHandle.ResponseNoLogin(request, respond);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public ActionResult GetAllAction()
        {
            var result = HuberPluginHandle.GetALlURL();

            return(Json(result.ToList(), JsonRequestBehavior.AllowGet));
        }