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:
swaggboi 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> <script>
function closeIt() { function closeIt() {
document.getElementById("gdpr").style.display = "none"; document.getElementById("gdpr").style.display = "none";
document.cookie = "banner=seen; max-age=600;"; document.cookie = "banner=seen; <%= $sessionLife %>;";
} }
function playIt() { function playIt() {

View File

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