public override void OnActionExecuting(ActionExecutingContext actionContext) { BaseResponse response = new BaseResponse(); if (actionContext.HttpContext?.User?.Identity != null && actionContext.HttpContext.User.Identity.IsAuthenticated) { var identity = (ClaimsIdentity)actionContext.HttpContext.User.Identity; Claim claim = identity.Claims.FirstOrDefault(s => s.Type == ClaimTypes.Name); if (claim == null) { response.IsCompleted = false; response.Message = "Invalid Authorization Token"; actionContext.Result = new JsonResult(response); } else { if (actionContext.HttpContext.Request.Method == HttpMethod.Post.Method) { var args = actionContext.ActionArguments?.Values; if (args != null) { var userId = SerializeJson <string> .Deserialize(claim.Value); foreach (var arg in args) { var specialProperties = arg.GetType().GetProperties().Where(pi => pi.GetCustomAttributes <UserControlAttribute>(true).Any()); foreach (var property in specialProperties) { var value = property.GetValue(arg); if (value.ToString() != userId) { response.IsCompleted = false; response.Message = "Geçersiz işlem."; actionContext.Result = new JsonResult(response); return; } } } } } base.OnActionExecuting(actionContext); } } else { response.IsCompleted = false; response.Message = "Invalid Authorization Token"; actionContext.Result = new JsonResult(response); } }
public MachineModel loadFromFile(string path) { SerializeJson serializeJson = new SerializeJson(typeof(MachineModel)); return((MachineModel)serializeJson.Deserialize(path)); }