Ejemplo n.º 1
0
        public ContentResult MenusToAdd(B_Menu menu)
        {
            menu.IsShow  = Request["IsShow"] != null && Request["IsShow"].ToString() == "on" ? true : false;
            menu.IsValid = Request["IsValid"] != null && Request["IsValid"].ToString() == "on" ? true : false;
            menu.IsRobot = Request["IsRobot"] != null && Request["IsRobot"].ToString() == "on" ? false : true;

            if (string.IsNullOrWhiteSpace(menu.MenuName))
            {
                return(Content("名称不能为空"));
            }
            if (RepeatHelper.NoRepeat("B_Menu", "MenuName", menu.MenuName, menu.ID) > 0)
            {
                return(Content("菜单名已存在"));
            }
            if (!string.IsNullOrWhiteSpace(menu.MenuUrl) && RepeatHelper.NoRepeat("B_Menu", "MenuUrl", menu.MenuUrl, menu.ID) > 0)
            {
                return(Content("菜单链接已存在"));
            }

            int rtn = menu.InsertAndReturnIdentity();

            if (rtn > 0)
            {
                bool hasMainMenuTag          = false;
                bool hasError                = false;
                List <B_MenuRights> muRights = null;
                if (string.IsNullOrWhiteSpace(menu.MenuUrl) == false)
                {
                    menu.MenuUrl = menu.MenuUrl.Trim().TrimEnd('/');
                    try
                    {
                        string[] arrUrl = menu.MenuUrl.TrimStart('/').Split('/');
                        Type     type   = Type.GetType("WeBusiness.Controllers." + arrUrl[0] + "Controller");
                        muRights = BaseAuthorizeHelper.GetBOMenuRightsByControllerType(type, arrUrl[1], out hasMainMenuTag);
                    }
                    catch (Exception ex)
                    {
                        DAL.Log.Instance.Write(ex.ToString(), "BOMenu_Add");
                        hasError = true;
                    }
                }

                if (hasMainMenuTag && muRights != null)
                {
                    B_MenuRights.RelevanceList(rtn, muRights);
                }
                if (hasError)
                {
                    return(Content("添加菜单成功,但菜单没有添加权限!"));
                }


                return(Content("ok"));
            }
            return(Content("添加出错"));
        }
Ejemplo n.º 2
0
 public ContentResult UpdateAllRights()
 {
     try
     {
         List <B_Menu> menus    = B_Menu.GetEntitysAll();
         string        ErrorStr = "";
         foreach (B_Menu menu in menus)
         {
             if (menu.ParentID == 0)
             {
                 continue;
             }
             bool hasMainMenuTag          = false;
             List <B_MenuRights> muRights = null;
             if (string.IsNullOrWhiteSpace(menu.MenuUrl) == false)
             {
                 menu.MenuUrl = menu.MenuUrl.Trim().TrimEnd('/');
                 try
                 {
                     string   tmpUrl = menu.MenuUrl.TrimStart('/').Split('?')[0];
                     string[] arrUrl = tmpUrl.Split('/');
                     Type     type   = Type.GetType("WeBusiness.Controllers." + arrUrl[0] + "Controller");
                     muRights = BaseAuthorizeHelper.GetBOMenuRightsByControllerType(type, arrUrl[1], out hasMainMenuTag);
                 }
                 catch (Exception ex)
                 {
                     DAL.Log.Instance.Write(ex.ToString(), "BOMenu_Update");
                     ErrorStr += "【" + menu.MenuName + "】";
                 }
             }
             if (hasMainMenuTag && muRights != null)
             {
                 B_MenuRights.RelevanceList(menu.ID, muRights);
             }
             B_MenuRights.ClearHashMenuRights();
         }
         if (!string.IsNullOrWhiteSpace(ErrorStr))
         {
             return(Content("更新失败的菜单:" + ErrorStr));
         }
         return(Content("ok"));
     }
     catch (Exception ex)
     {
         DAL.Log.Instance.Write(ex.ToString(), "B_Menu_UpdateAllRights_error");
         return(Content("更新失败"));
     }
 }
Ejemplo n.º 3
0
        //
        // GET: /Home/

        public ActionResult Index(string url)
        {
            try
            {
                BaseAuthorizeModel auth = BaseAuthorizeHelper.GetAuthorizeModel(this.HttpContext);
                if (string.IsNullOrWhiteSpace(auth.TempDataMsg) == false)
                {
                    TempData["Msg"] = auth.TempDataMsg;
                }
                if (auth.IsAuthorize == false)
                {
                    string userAgent = Request.UserAgent;
                    return(RedirectToAction("Login", "Home", new { url = Request.Url.ToString() }));
                }
                B_User        user  = auth.CurrentSYSUser;
                List <B_Menu> menus = B_Menu.GetShowMenus();

                if (user.UserName != WeConfig.robot)
                {
                    menus.RemoveAll(m => m.IsRobot);
                }

                List <B_Role>       roles     = B_Role.GetUserRoles(user.UserName);
                List <B_MenuRights> rolerignt = B_MenuRights.GetRoleUser(roles[0].ID);
                ViewData["role"]     = (roles != null && roles.Count > 0) ? roles[0] : null;
                ViewData["menus"]    = menus;
                ViewData["url"]      = url;
                ViewData["UserRole"] = rolerignt;

                return(View(user));
            }
            catch (Exception ex)
            {
                DAL.Log.Instance.Write(ex.ToString());
                return(View(ErrorPage.ViewName, new ErrorPage {
                    Message = ex.ToString()
                }));
            }
        }
Ejemplo n.º 4
0
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            ReflectedActionDescriptor descriptor = filterContext.ActionDescriptor as ReflectedActionDescriptor;

            if (descriptor != null)
            {
                Type actionType = descriptor.MethodInfo.ReturnType;
                if (actionType.Equals(typeof(ActionResult)))
                {
                    if (actionType.IsSubclassOf(typeof(JsonResult)))
                    {
                        actionResult = ReturnResult.Json;
                    }
                    else if (actionType.IsSubclassOf(typeof(ContentResult)))
                    {
                        actionResult = ReturnResult.Content;
                    }
                }
                else
                {
                    if (actionType.Equals(typeof(JsonResult)))
                    {
                        actionResult = ReturnResult.Json;
                    }
                    else if (actionType.Equals(typeof(ContentResult)))
                    {
                        actionResult = ReturnResult.Content;
                    }
                }
            }

            _ActionName     = filterContext.ActionDescriptor.ActionName;
            _ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            string _ControllerType = filterContext.ActionDescriptor.ControllerDescriptor.ControllerType.ToString();

            if (_ControllerType != "WeBusiness.Controllers." + _ControllerName + "Controller")
            {
                filterContext.Result = GetErrorResult("若继承BaseController则该控制器只能使用默认后缀Controller和命名空间只能使用WeBusiness.Controllers", null, false);
                return;
            }

            BaseAuthorizeModel auth = BaseAuthorizeHelper.GetAuthorizeModel(filterContext.HttpContext, CurrentURL);

            if (string.IsNullOrWhiteSpace(auth.GuidCode) == false)
            {
                GuidCode = auth.GuidCode;
            }

            string _loginfo = "异常退出";

            if (string.IsNullOrWhiteSpace(auth.TempDataMsg) == false)
            {
                TempData["Msg"] = auth.TempDataMsg;
                _loginfo        = auth.TempDataMsg;
            }

            if (auth.IsAuthorize == false)
            {
                //异常退出
                logType = SYSLogType.Other;
                logInfo = _loginfo;
                logUser = auth.UserName;
                //WriteSYSLog();

                filterContext.Result = GetErrorResult(auth.TempDataMsg, null, true);
            }
            else
            {
                CurrentUser = auth.CurrentSYSUser;
                logUser     = CurrentUser.UserName;
            }
        }