public ActionResult ViewAuth(int id) { RoleAuthModel model = new RoleAuthModel(); IPlatformRoleBLL platformRoleBll = BLLFactory <IPlatformRoleBLL> .GetBLL("PlatformRoleBLL"); //获取要查看权限的平台角色 T_PlatformRole role = platformRoleBll.GetEntity(m => m.Id == id); //赋值 要查看权限的平台角色 model.Role = new RoleModel() { RoleId = role.Id, RoleName = role.RoleName, RoleMemo = role.RoleMemo }; //如果是普通角色 if (role.IsSystem == ConstantParam.USER_ROLE_DEFAULT) { //赋值 该角色所有的权限ID集合 model.ActionIds = role.PlatformRoleActions.Select(m => m.ActionId).ToList(); //Model赋值 该角色所关联的非重复菜单 var roleMenuList = role.PlatformRoleActions.Select(m => m.Action.Menu).Distinct().OrderBy(m => m.Order).ToList(); //新定义展示Model树形菜单 var menuList = new List <M_Menu>(); foreach (var menu in roleMenuList) { if (menu.ParentId != null) { if (!menuList.Contains(menu.ParentMenu)) { menuList.Add(menu.ParentMenu); } } menuList.Add(menu); } model.MenuList = menuList; } else { IActionBLL actionBll = BLLFactory <IActionBLL> .GetBLL("ActionBLL"); //赋值 所有的平台权限 model.ActionIds = actionBll.GetList(a => a.Menu.IsPlatform == ConstantParam.USER_TYPE_PLATFORM).Select(a => a.Id).ToList(); IMenuBLL menuBll = BLLFactory <IMenuBLL> .GetBLL("MenuBLL"); //Model赋值 所有的平台菜单 model.MenuList = menuBll.GetList(m => m.IsPlatform == ConstantParam.USER_TYPE_PLATFORM).ToList(); } return(View(model)); }
/// <summary> /// 添加操作记录 /// </summary> /// <param name="content">操作数据内容</param> public void AddOpreateLog(string content, UserSessionModel model, string reqUrl) { try { IActionBLL actionBll = BLLFactory <IActionBLL> .GetBLL("ActionBLL"); //获取到请求地址对应的权限 var act = actionBll.GetEntity(a => a.Href.Equals(reqUrl)); //如果当前为平台后台用户 if (model.UserType == ConstantParam.USER_TYPE_PLATFORM) { T_PlatformOpreateLog log = new T_PlatformOpreateLog() { Action = act.ActionName, Desc = content, OpreaterId = model.UserID, OpreateTime = DateTime.Now }; IPlatformOpreateLogBLL bll = FactoryBLL.BLLFactory <IPlatformOpreateLogBLL> .GetBLL("PlatformOpreateLogBLL"); bll.Save(log); } else if (model.UserType == ConstantParam.USER_TYPE_PROPERTY) { T_PropertyOpreateLog log = new T_PropertyOpreateLog() { Action = act.ActionName, Desc = content, OpreaterId = model.UserID, OpreateTime = DateTime.Now }; IPropertyOpreateLogBLL bll = FactoryBLL.BLLFactory <IPropertyOpreateLogBLL> .GetBLL("PropertyOpreateLogBLL"); bll.Save(log); } else if (model.UserType == ConstantParam.USER_TYPE_COMPANY) { T_CompanyOpreateLog log = new T_CompanyOpreateLog() { Action = act.ActionName, Desc = content, OpreaterId = model.UserID, OpreateTime = DateTime.Now }; ICompanyOpreateLogBLL bll = FactoryBLL.BLLFactory <ICompanyOpreateLogBLL> .GetBLL("CompanyOpreateLogBLL"); bll.Save(log); } } catch { } }
/// <summary> /// 判断用户是否显示该按钮权限 /// </summary> /// <param name="url">地址</param> /// <returns></returns> public static bool IsHasButton(this HtmlHelper html, string url) { if (string.IsNullOrEmpty(url)) { return(false); } //获取session对象 var session = HttpContext.Current.Session; //获取 UserSessionModel model = (UserSessionModel)session[ConstantParam.SESSION_USERINFO]; //普通用户 if (model.IsMgr == ConstantParam.USER_ROLE_DEFAULT) { if (model.ActionDic.ContainsKey(url)) { return(true); } //获取到请求地址对应的权限 IActionBLL actionBll = BLLFactory <IActionBLL> .GetBLL("ActionBLL"); var act = actionBll.GetEntity(a => a.Href.Equals(url)); //如果是平台用户,菜单为物业菜单,则拥有该按钮权限 if (act != null && act.Menu.IsPlatform == 0 && model.UserType == ConstantParam.USER_TYPE_PLATFORM) { return(true); } } else { return(true); } return(false); }
/// <summary> /// 在某个action执行之前进行拦截 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { //1.获取登录的session信息 HttpContextBase ctx = filterContext.HttpContext; var model = (UserSessionModel)ctx.Session[ConstantParam.SESSION_USERINFO]; //获取请求地址 string controller = filterContext.RouteData.Values["controller"].ToString(); string action = filterContext.RouteData.Values["action"].ToString(); string reqUrl = "/" + controller + "/" + action; //获取到请求地址对应的权限 IActionBLL actionBll = BLLFactory <IActionBLL> .GetBLL("ActionBLL"); var act = actionBll.GetEntity(a => a.Href.Equals(reqUrl)); if (act == null) { IActionItemBLL actionItemBll = BLLFactory <IActionItemBLL> .GetBLL("ActionItemBLL"); var actionItem = actionItemBll.GetEntity(i => i.Href.Equals(reqUrl)); if (actionItem != null) { act = actionItem.Action; } } //判断是否为空 if (model == null) { if (act != null) { //进行注销 if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_PLATFORM) { filterContext.Result = new RedirectResult("~/Account/PlatformLogOff"); } else if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_PROPERTY) { filterContext.Result = new RedirectResult("~/Account/PropertyLogOff"); } else if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_COMPANY) { filterContext.Result = new RedirectResult("~/Account/CompanyPlatformLogOff"); } } } //如果要访问物业平台,但没保存当前小区 else if (act != null && act.Menu.IsPlatform == ConstantParam.USER_TYPE_PROPERTY && model.PropertyPlaceId == null) { filterContext.Result = new RedirectResult("~/Account/PropertyLogOff"); } //权限验证 //判断用户类型-普通用户的场合 else if (model.IsMgr == ConstantParam.USER_ROLE_DEFAULT) { //如果请求地址不在权限字典中 if (!model.ActionDic.ContainsKey(reqUrl)) { //如果访问后台,进行注销 if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_PLATFORM) { filterContext.Result = new RedirectResult("~/Account/PlatformLogOff"); } //如果访问物业总公司平台 else if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_COMPANY) { filterContext.Result = new RedirectResult("~/Account/CompanyPlatformLogOff"); } else if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_PROPERTY) { //如果是物业用户访问物业平台,进行注销 if (model.UserType == ConstantParam.USER_TYPE_PROPERTY) { filterContext.Result = new RedirectResult("~/Account/PropertyLogOff"); } } } } else { if (act != null) { //如果非后台用户访问后台 if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_PLATFORM) { if (model.UserType != ConstantParam.USER_TYPE_PLATFORM) { //进行注销 filterContext.Result = new RedirectResult("~/Account/PlatformLogOff"); } } //如果非后台或物业用户访问物业平台 else if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_PROPERTY) { if (model.UserType != ConstantParam.USER_TYPE_PLATFORM && model.UserType != ConstantParam.USER_TYPE_PROPERTY) { //进行注销 filterContext.Result = new RedirectResult("~/Account/PropertyLogOff"); } } //如果非总公司用户访问总公司平台 else if (act.Menu.IsPlatform == ConstantParam.USER_TYPE_COMPANY) { if (model.UserType != ConstantParam.USER_TYPE_COMPANY) { //进行注销 filterContext.Result = new RedirectResult("~/Account/CompanyPlatformLogOff"); } } } } base.OnActionExecuting(filterContext); }