From 051ff9a912e9028626bce35bcca460281c6bec4b Mon Sep 17 00:00:00 2001 From: swaggboi Date: Sat, 13 Mar 2021 02:15:04 -0500 Subject: [PATCH] Implement `under` for session cookie --- www-swagg.pl | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/www-swagg.pl b/www-swagg.pl index d8d4bab..cd7a33d 100755 --- a/www-swagg.pl +++ b/www-swagg.pl @@ -8,26 +8,23 @@ use Regexp::Common qw{net}; use Digest::SHA qw{sha1_hex}; use Number::Format qw{format_number}; -## Let's set some things up first ## - plugin 'Config'; # CGI scripts plugin CGI => ['/cgi-bin/guest' => './cgi-bin/guest_mm.cgi']; plugin CGI => ['/cgi-bin/whoami' => './cgi-bin/whoami.cgi' ]; -# Handle the GDPR non-compliance banner via session cookie -helper swaggSession => sub { +under sub { my ($c) = @_; if ($c->cookie('banner') eq 'seen') { $c->session->{banner} = 'seen' unless $c->session->{banner} } + + return 1; }; -## Begin routes ## - -# The main landing page; pass in the output of the fortune command +# The main landing page; index.html get '/' => sub { my ($c) = @_; my $count = format_number time; # Grab epoch and add commas @@ -38,8 +35,6 @@ get '/' => sub { fortune => $fortune ); - $c->swaggSession(); - $c->render(); } => 'index'; @@ -92,22 +87,17 @@ get '/ula6' => sub { $ula6 = $uniqueid . ':/48'; } - $c->swaggSession(); - $c->render(ula6 => $ula6); }; -# Catch any other route +# Default route get '/:route' => [route => [qw{die me news}]] => sub { my ($c) = @_; my $route = $c->stash('route'); - $c->swaggSession(); - $c->render(template => $route); }; -## Send it ## - +# Send it app->secrets(app->config->{secrets}) || die $!; app->start();