/// <summary> /// 验证登录等信息 /// </summary> /// <param name="context"></param> public override void OnActionExecuting(ActionExecutingContext context) { if (context.HttpContext == null || context.HttpContext.Session == null) { throw new Exception("此特性只适合于Web应用程序使用或者您的服务器Session不可用!"); } //首先读取用户登录的Session信息进行判断 string userJson = context.HttpContext.Session.GetString(KeyUtil.user_info_front); if (!string.IsNullOrEmpty(userJson)) { UserSession userSession = JsonNetHelper.DeserializeObject <UserSession>(userJson); if (string.IsNullOrEmpty(userSession.user_id)) { context.HttpContext.Session.SetString(KeyUtil.user_info, ""); context.Result = new RedirectToActionResult("Index", "Login", null); } else { base.OnActionExecuting(context); } } else { context.Result = new RedirectToActionResult("Index", "Login", null); } }
/// <summary> /// 根据用户Id和路径查询按钮集合并且返回(使用redis实现) /// </summary> /// <returns></returns> public async Task <IViewComponentResult> InvokeAsync() { UserSession userSession = JsonNetHelper.DeserializeObject <UserSession>(HttpContext.Session.GetString(KeyUtil.user_info)); List <MenuActionInfo> result = null; if (redisHelp._conn != null) { string key = string.Format(RedisKeyUtil.login_admin_menu, userSession.user_id); if (redisHelp.KeyExists(key)) { result = JsonNetHelper.DeserializeObject <List <MenuActionInfo> >(await redisHelp.StringGetAsync(key)); } else { result = await userService.GetMenuInfo(userSession.user_id); await redisHelp.StringSetAsync(key, JsonNetHelper.SerializeObject(result), new TimeSpan(30, 12, 60)); } } else { result = await userService.GetMenuInfo(userSession.user_id); } return(View("MenuInfo", result)); }
public override void ExecuteResult(ControllerContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (JsonRequestBehavior == JsonRequestBehavior.DenyGet && string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException("JSON GET is not allowed"); } HttpResponseBase response = context.HttpContext.Response; response.ContentType = string.IsNullOrEmpty(this.ContentType) ? "application/json" : this.ContentType; if (ContentEncoding != null) { response.ContentEncoding = this.ContentEncoding; } if (Data == null) { return; } var json = JsonNetHelper.Serialize(this.Data); response.Write(json); }
private T SendCommand <T>(Uri endpoint, object payload = null) where T : class { var httpWebRequest = (HttpWebRequest)WebRequest.Create(endpoint); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; httpWebRequest.Accept = "application/json"; httpWebRequest.Headers.Add(ServerConfiguration.Headers.Version, (typeof(ServerChannel).Assembly.GetName().Version.ToString())); httpWebRequest.Headers.Add(ServerConfiguration.Headers.WorkerRegistrationToken, Token.HasValue?Token.ToString():""); using (var writer = new StreamWriter(httpWebRequest.GetRequestStream())) { writer.Write(JsonNetHelper.Serialize(payload)); } using (var reader = new StreamReader(httpWebRequest.GetResponse().GetResponseStream())) { var body = reader.ReadToEnd(); try { return(JsonNetHelper.Deserialize <T>(body)); } catch (JsonException ex) { Logger.Error(ex); Logger.Error(body); throw; } } }
/// <summary> /// 验证登录等信息 /// </summary> /// <param name="context"></param> public override void OnActionExecuting(ActionExecutingContext context) { if (context.HttpContext == null || context.HttpContext.Session == null) { throw new Exception("此特性只适合于Web应用程序使用或者您的服务器Session不可用!"); } //首先判断用户是否登陆读取到Session,如果没有读取则直接返回登陆页面 string user_json = context.HttpContext.Session.GetString(KeyUtil.user_info); if (!string.IsNullOrEmpty(user_json)) { UserSession userSession = JsonNetHelper.DeserializeObject <UserSession>(user_json); //根据用户Id和请求路劲查询此页面是否可以访问,如果不能访问,则跳转到登录页面 ControllerActionDescriptor action = (ControllerActionDescriptor)context.ActionDescriptor; string actionurl = string.Format("/{0}/{1}/{2}", action.RouteValues["area"], action.RouteValues["controller"], action.RouteValues["action"]).ToLower(); //判断是否含有访问这个字段的权限,如果有,则继续,否则跳转到登录页 if (userSession.action_url == null || !userSession.action_url.Contains(actionurl)) { context.HttpContext.Session.SetString(KeyUtil.user_info, ""); context.Result = new RedirectToActionResult("Index", "Login", null); } else { base.OnActionExecuting(context); } } else { context.Result = new RedirectToActionResult("Index", "Login", null); } }
/// <summary> /// 根据用户Id和路径查询按钮集合并且返回 /// </summary> /// <returns></returns> public async Task <IViewComponentResult> InvokeAsync() { UserSession userSession = JsonNetHelper.DeserializeObject <UserSession>(HttpContext.Session.GetString(KeyUtil.user_info)); string current_url = HttpContext.Request.Path; var result = await userService.getButtionInfo(userSession.user_id, current_url); return(View("ButtionInfo", result)); }
public override IValueProvider GetValueProvider(ControllerContext controllerContext) { // first make sure we have a valid context if (controllerContext == null) { throw new ArgumentNullException("controllerContext"); } // now make sure we are dealing with a json request if ( !controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase)) { return(null); } // get a generic stream reader (get reader for the http stream) object jsonObject; using (var streamReader = new StreamReader(controllerContext.HttpContext.Request.InputStream)) { using (var JSONReader = new JsonTextReader(streamReader)) { if (!JSONReader.Read()) { return(null); } // make a new Json serializer //var JSONSerializer = JsonNetHelper.CreateDefault(JsonNetHelper.GetSerializerSettings()); //// add the dyamic object converter to our serializer //JSONSerializer.Converters.Add(new ExpandoObjectConverter()); // use JSON.NET to deserialize object to a dynamic (expando) object // if we start with a "[", treat this as an array if (JSONReader.TokenType == JsonToken.StartArray) { jsonObject = JsonNetHelper.Deserialize <List <ExpandoObject> >(JSONReader.ReadAsString()); } else { jsonObject = JsonNetHelper.Deserialize <ExpandoObject>(JSONReader.ReadAsString()); } } } // create a backing store to hold all properties for this deserialization var backingStore = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); // add all properties to this backing store AddToBackingStore(backingStore, String.Empty, jsonObject); // return the object in a dictionary value provider so the MVC understands it return(new DictionaryValueProvider <object>(backingStore, CultureInfo.CurrentCulture)); }
/// <summary> /// 返回登录用户的user_id /// </summary> /// <returns></returns> public string return_front_userid() { string userJson = HttpContext.Session.GetString(KeyUtil.user_info_front); if (string.IsNullOrEmpty(userJson)) { return(""); } UserSession userSession = JsonNetHelper.DeserializeObject <UserSession>(userJson); return(userSession.user_id); }
/// <summary> /// 返回用户登录的Session信息 /// </summary> /// <returns></returns> public UserSession GetUserSession() { string userJson = HttpContext.Session.GetString(KeyUtil.user_info); if (string.IsNullOrEmpty(userJson)) { return(null); } UserSession userSession = JsonNetHelper.DeserializeObject <UserSession>(userJson); return(userSession); }
public string GetLoginLogData(int page, int limit) { int count; IEnumerable <LoginLogOutput> loginLog = _logManageService.GetLoginLogOutputs(page, limit, out count); DataResult <IEnumerable <LoginLogOutput> > data = new DataResult <IEnumerable <LoginLogOutput> > { msg = "获取成功!", code = 0, count = count, data = loginLog }; return(JsonNetHelper.SerialzeoJsonForCamelCase(data)); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if ( !controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase)) { return(_defaultModelBinder.BindModel(controllerContext, bindingContext)); } controllerContext.HttpContext.Request.InputStream.Position = 0; using (var streamReader = new StreamReader(controllerContext.HttpContext.Request.InputStream)) { var json = streamReader.ReadToEnd(); Log.Info("Json " + json); return(JsonNetHelper.Deserialize(json)); } }
/// <summary> /// 获取部门信息(用于部门信息页面展示) /// </summary> /// <param name="page"></param> /// <param name="limit"></param> /// <param name="queryInfo"></param> /// <returns></returns> public string GetDepartmentInfo(int page, int limit, string queryInfo) { if (!string.IsNullOrEmpty(queryInfo)) { queryInfo = queryInfo.Trim(); } int count; IEnumerable <DepartmentOutput> departments = _departmentManageService.GetDepartments(page, limit, out count, queryInfo); DataResult <IEnumerable <DepartmentOutput> > data = new DataResult <IEnumerable <DepartmentOutput> > { msg = "获取成功!", code = 0, count = count, data = departments }; return(JsonNetHelper.SerialzeoJsonForCamelCase(data)); }
public string GetFinishedOrder(int page, int limit, string queryInfo) { if (!string.IsNullOrEmpty(queryInfo)) { queryInfo = queryInfo.Trim(); } int count; IEnumerable <DemandOrderOutput> finishedOrder = _orderManageService.GetFinishedOrder(page, limit, out count, queryInfo); DataResult <IEnumerable <DemandOrderOutput> > data = new DataResult <IEnumerable <DemandOrderOutput> > { msg = "获取成功!", code = 0, count = count, data = finishedOrder }; return(JsonNetHelper.SerialzeoJsonForCamelCase(data)); }
public string GetCategoriesList(int page, int limit, string queryInfo) { if (!string.IsNullOrEmpty(queryInfo)) { queryInfo = queryInfo.Trim(); } int count; IEnumerable <CategoryOutput> categories = _categoryManageService.GetCategories(page, limit, out count, queryInfo); DataResult <IEnumerable <CategoryOutput> > data = new DataResult <IEnumerable <CategoryOutput> > { msg = "获取成功!", code = 0, count = count, data = categories }; return(JsonNetHelper.SerialzeoJsonForCamelCase(data)); }
public string GetBills(int page, int limit, string queryInfo) { if (!string.IsNullOrEmpty(queryInfo)) { queryInfo = queryInfo.Trim(); } int count; IEnumerable <RevenueOutput> revenues = _financialManageService.GetBills(page, limit, out count, queryInfo); DataResult <IEnumerable <RevenueOutput> > data = new DataResult <IEnumerable <RevenueOutput> > { msg = "获取成功!", code = 0, count = count, data = revenues }; return(JsonNetHelper.SerialzeoJsonForCamelCase(data)); }
public string GetWareHouseDataList(int page, int limit, string queryInfo) { if (!string.IsNullOrEmpty(queryInfo)) { queryInfo = queryInfo.Trim(); } int count; IEnumerable <WareHouseOutput> Info = _wareHouseService.GetGoodsOutputs(page, limit, out count, queryInfo); DataResult <IEnumerable <WareHouseOutput> > data = new DataResult <IEnumerable <WareHouseOutput> > { msg = "获取成功!", code = 0, count = count, data = Info }; return(JsonNetHelper.SerialzeoJsonForCamelCase(data)); }
public static T SendRequest <T>(Uri endpoint, object payload = null) where T : class { var httpWebRequest = (HttpWebRequest)WebRequest.Create(endpoint); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; httpWebRequest.Accept = "application/json"; httpWebRequest.Headers.Add(ServerConfiguration.Headers.Version, typeof(Program).Assembly.GetName().Version.ToString()); using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(JsonNetHelper.Serialize(payload)); streamWriter.Flush(); streamWriter.Close(); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); return(JsonNetHelper.Deserialize <T>(result)); } } }
public string GetMyWaittingVerifyOrder(int page, int limit, string queryInfo) { string userId = HttpContext.Session.GetString("UserId"); if (string.IsNullOrEmpty(userId)) { return("未登录!或登录已失效"); } if (!string.IsNullOrEmpty(queryInfo)) { queryInfo = queryInfo.Trim(); } int count; IEnumerable <OrderOutput> orders = _orderManageService.GetMyWaittingConfirmOrder(page, limit, out count, queryInfo, userId); DataResult <IEnumerable <OrderOutput> > data = new DataResult <IEnumerable <OrderOutput> > { msg = "获取成功!", code = 0, count = count, data = orders }; return(JsonNetHelper.SerialzeoJsonForCamelCase(data)); }
public string GetRuningSpecialOrders(int page, int limit, string queryInfo) { string userId = HttpContext.Session.GetString("UserId"); if (string.IsNullOrEmpty(userId)) { return("未登录!或登录已失效"); } if (!string.IsNullOrEmpty(queryInfo)) { queryInfo = queryInfo.Trim(); } int count; IEnumerable <WorkFlowOutput> workFlowOrder = _orderManageService.GetFlowOutputs(page, limit, out count, queryInfo, userId); DataResult <IEnumerable <WorkFlowOutput> > data = new DataResult <IEnumerable <WorkFlowOutput> > { msg = "获取成功!", code = 0, count = count, data = workFlowOrder }; return(JsonNetHelper.SerialzeoJsonForCamelCase(data)); }
public async Task <BaseResult <bool> > Login(string login_name_in, string user_pwd_in) { if (string.IsNullOrEmpty(login_name_in) || string.IsNullOrEmpty(user_pwd_in)) { return(new BaseResult <bool>(808, false)); } //这里可以用邮箱和手机号登陆,需要判断使用什么方式登录,查询用户信息之后验证是否可以访问 Expression <Func <UserEntity, bool> > where = LinqUtil.True <UserEntity>(); where = RegexUtil.Email(login_name_in) ? where.AndAlso(c => c.user_email == login_name_in) : where.AndAlso(c => c.user_phone == login_name_in); where = where.AndAlso(c => c.user_pwd == CommonUtil.Md5(user_pwd_in)); UserEntity userEntity = await userRepository.GetAsync(where); if (userEntity == null) { return(new BaseResult <bool>(1000, false)); } if (userEntity.disable == (int)DisableStatus.disable_true) { return(new BaseResult <bool>(1004, false)); } if (userEntity.user_activation == (int)DisableStatus.disable_true) { return(new BaseResult <bool>(1005, false)); } if (userEntity.user_visit == (int)DisableStatus.disable_true) { return(new BaseResult <bool>(1006, false)); } //用户登录正常,修改用户登录时间并且将登录的信息保存到Session中 await userRepository.UpdateAsync(new UserEntity() { user_id = userEntity.user_id, last_time = DateTime.Now }, true, true, c => c.last_time); //处理信息,如果redis连接成功,则直接判断是否存在值,如果存在,则直接使用,否则直接查询并且保存 ,如果连接失败,则直接查询 List <string> buttionActions = null; if (redisHelp._conn != null) { string key = string.Format(RedisKeyUtil.login_admin, userEntity.user_id); if (redisHelp.KeyExists(key)) { buttionActions = JsonNetHelper.DeserializeObject <List <string> >(await redisHelp.StringGetAsync(key)); } else { buttionActions = buttonActionRepository.GetMenuInfo(userEntity.user_id, c => c.action_type != (int)ActionType.front && c.action_url != null && c.disable == (int)DisableStatus.disable_false).Select(c => c.action_url).ToList(); await redisHelp.StringSetAsync(key, JsonNetHelper.SerializeObject(buttionActions), new TimeSpan(30, 12, 60)); } } else { buttionActions = buttonActionRepository.GetMenuInfo(userEntity.user_id, c => c.action_type != (int)ActionType.front && c.action_url != null && c.disable == (int)DisableStatus.disable_false).Select(c => c.action_url).ToList(); } UserSession userSession = new UserSession { user_id = userEntity.user_id, user_name = userEntity.user_name + userEntity.user_code, user_image = userEntity.user_image, full_name = userEntity.full_name, action_url = buttionActions == null ? null : buttionActions }; httpContextUtil.setObjectAsJson(KeyUtil.user_info, userSession); return(new BaseResult <bool>(200, true)); }