/// <summary> /// 获取资源描述 /// </summary> /// <param name="resourceKey"></param> /// <returns></returns> public string GetResourceDescriptionByKey(string resourceKey) { var resources = new MongoDbStore<System_Resources>("Resources"); var resource = resources.Single(r => r.Key.ToLower() == resourceKey); if (resource == null) return resourceKey; if (resource.ParentCode == null || resource.ParentCode == "0") return resource.Description == null ? resourceKey : resource.Description; return GetResourceDescriptionByCode(resource.ParentCode, resource.Description); }
/// <summary> /// The get system user session. /// </summary> /// <param name="sessionId"> /// The session id. /// </param> /// <returns> /// The <see cref="SystemUserSession"/>. /// </returns> public static SystemUserSession GetSystemUserSession(string sessionId) { var mongoDbStore = new MongoDbStore<SystemUserSession>("SystemUserSessions"); var systemUserSession = mongoDbStore.Single(item => item.SessionID == sessionId); if (systemUserSession != null) { return systemUserSession; } else { return null; } }
/// <summary> /// The refresh session. /// </summary> /// <param name="userSession"> /// The user session. /// </param> public static void RefreshSystemUserSession(SystemUserSession userSession) { var mongoDbStore = new MongoDbStore<SystemUserSession>("SystemUserSessions"); var systemUserSession = mongoDbStore.Single(item => item.SessionID == userSession.SessionID); if (systemUserSession != null) { mongoDbStore.Delete(s => s.SessionID == userSession.SessionID); } mongoDbStore.Insert(userSession); }
/// <summary> /// 获取或设置省/市/区县编号. /// </summary> public string CountyName(string splite) { if (this.CountyID < 1) { return null; } var countyList = new MongoDbStore<County>("Counties"); var county = countyList.Single(item => item.ID == this.CountyID); if (county == null) { return null; } var cityList = new MongoDbStore<City>("Cities"); var city = cityList.Single(item => item.ID == county.CityID); if (city == null) { return null; } var provinceList = new MongoDbStore<Province>("Provinces"); var provice = provinceList.Single(item => item.ID == city.ProvinceID); if (provice == null) return null; return provice.Name + splite + city.Name + splite + county.Name; }
/// <summary> /// The on action executing. /// </summary> /// <param name="filterContext"> /// The filter context. /// </param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { string resourceKey = string.Empty; string resourceDescription = string.Empty; var mongoDbStore = new MongoDbStore<SystemUserSession>("SystemUserSessions"); systemUserSession = mongoDbStore.Single(item => item.SessionID == Session.SessionID); if (systemUserSession == null) { HandleSessionLost(filterContext); } else { // todo: 会话失效判断 //this.HandleSessionState(filterContext, mongoDbStore); var systemRightService = new SystemRightsService(); resourceKey = this.GetResourceKey(filterContext); resourceDescription = systemRightService.GetResourceDescriptionByKey(resourceKey); if (!systemRightService.ValidateRight(resourceKey, this.systemUserSession.Permissions)) { if (!this.ValidateAjaxRequest(filterContext)) { filterContext.Result = this.Content("<script type='text/javascript'>alert('对不起,您没有此操作权限!');</script>"); } else { Response.StatusCode = 610; filterContext.Result = this.Json(new AjaxResponse(-403, "无操作权限"), JsonRequestBehavior.AllowGet); } LogUtils.Log( "无操作权限" + resourceDescription, "OnActionExecuting", Category.Info, systemUserSession.SessionID, systemUserSession.SystemUserID, "Enter"); } } if (systemUserSession == null) { LogUtils.Log("未登录", "OnActionExecuting"); } else { LogUtils.Log( "用户“" + systemUserSession.Name + "”,正在操作:" + resourceDescription, "OnActionExecuting", Category.Info, systemUserSession.SessionID, systemUserSession.SystemUserID, "Enter"); } base.OnActionExecuting(filterContext); }