Skip to content

Commit

Permalink
Ignore cookies if it's been more than 100 minutes #105
Browse files Browse the repository at this point in the history
  • Loading branch information
programcsharp committed Mar 21, 2020
1 parent 9ec3a73 commit 44d9408
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions Griddly.Mvc/GriddlyContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ public class GriddlyFilterCookieData
{
public Dictionary<string, string[]> Values { get; set; }
public SortField[] SortFields { get; set; }
public DateTime? CreatedUtc { get; set; }
}
}
14 changes: 10 additions & 4 deletions Griddly.Mvc/GriddlyCookieFilterValueProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ public override IValueProvider GetValueProvider(ControllerContext controllerCont
{
var data = JsonConvert.DeserializeObject<GriddlyFilterCookieData>(cookie.Value);

context.CookieData = data;
context.IsDefaultSkipped = true;

return new GriddlyCookieFilterValueProvider(context);
// chrome/ff don't delete session cookies if they're set to "continue where you left off"
// https://stackoverflow.com/questions/10617954/chrome-doesnt-delete-session-cookies
// only use a cookie if it's new within 100 minutes
if (data.CreatedUtc != null && (DateTime.UtcNow - data.CreatedUtc.Value).TotalMilliseconds < 100)
{
context.CookieData = data;
context.IsDefaultSkipped = true;

return new GriddlyCookieFilterValueProvider(context);
}
}
catch
{
Expand Down
3 changes: 2 additions & 1 deletion Griddly.Mvc/GriddlyParameterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public override void OnActionExecuted(ActionExecutedContext filterContext)

GriddlyFilterCookieData data = new GriddlyFilterCookieData()
{
Values = new Dictionary<string, string[]>()
Values = new Dictionary<string, string[]>(),
CreatedUtc = DateTime.UtcNow
};

if (context.SortFields?.Length > 0)
Expand Down

0 comments on commit 44d9408

Please sign in to comment.