Refine the new cookie/session behavior

Session is now a variable; applies to plain-text and session cookies (controller and passed throught to layout via stash())
This commit is contained in:
swagg boi 2021-03-29 15:02:41 -04:00
parent 392f55a791
commit 13924d7f61
2 changed files with 7 additions and 3 deletions

View file

@ -25,7 +25,7 @@
<script>
function closeIt() {
document.getElementById("gdpr").style.display = "none";
document.cookie = "banner=seen; max-age=600;";
document.cookie = "banner=seen; <%= $sessionLife %>;";
}
function playIt() {

View file

@ -17,14 +17,18 @@ plugin CGI => ['/cgi-bin/whoami.cgi' => './cgi-bin/whoami.cgi' ];
# Handle the session
under sub {
my ($c) = @_;
my $sessionLife = 604800;
if ($c->cookie('banner') eq 'seen') {
# Set session for a week
$c->session(expiration => 604800)->{banner} //= 'seen';
$c->session(expiration => $sessionLife, banner => 'seen');
# Kill plain-text cookie
$c->cookie(banner => 'seen', {expires => 1});
}
# Pass in the expiration for plain-text cookie
$c->stash(sessionLife => $sessionLife);
1;
};