From 13447382a209dc3b263732443e448c0700f711e1 Mon Sep 17 00:00:00 2001 From: Al Beano Date: Sun, 16 Jul 2017 23:12:38 +0100 Subject: [PATCH] More rigorous auth-checking --- lib/cyberman/Domains.pm | 8 +++++--- lib/cyberman/Helper.pm | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 lib/cyberman/Helper.pm diff --git a/lib/cyberman/Domains.pm b/lib/cyberman/Domains.pm index e3f7508..92f709b 100644 --- a/lib/cyberman/Domains.pm +++ b/lib/cyberman/Domains.pm @@ -3,10 +3,10 @@ package cyberman::Domains; use Dancer2 appname => "cyberman"; use Dancer2::Plugin::Database; +use cyberman::Helper qw(auth_test); + get '/domains' => sub { - return template 'redir' => { - "redir" => "index", - } unless vars->{"auth"}; + return auth_test() if auth_test(); my @domains = database->quick_select( "domain", @@ -21,6 +21,8 @@ get '/domains' => sub { }; post '/domains/new' => sub { + return auth_test() if auth_test(); + my %errs; if (!param("name")) { diff --git a/lib/cyberman/Helper.pm b/lib/cyberman/Helper.pm new file mode 100644 index 0000000..f709a53 --- /dev/null +++ b/lib/cyberman/Helper.pm @@ -0,0 +1,18 @@ +package cyberman::Helper; +use base qw(Exporter); +use Dancer2 appname => "cyberman"; +use Exporter qw(import); + +our @EXPORT = qw(auth_test); + +sub auth_test { + if (!vars->{"auth"}) { + return template 'redir' => { + "redir" => "/index", + }; + } else { + return 0; # nothing to be returned, route can continue + } +} + +1;