More rigorous auth-checking

This commit is contained in:
Al Beano 2017-07-16 23:12:38 +01:00
parent ec72bd2a1e
commit 13447382a2
2 changed files with 23 additions and 3 deletions

View File

@ -3,10 +3,10 @@ package cyberman::Domains;
use Dancer2 appname => "cyberman"; use Dancer2 appname => "cyberman";
use Dancer2::Plugin::Database; use Dancer2::Plugin::Database;
use cyberman::Helper qw(auth_test);
get '/domains' => sub { get '/domains' => sub {
return template 'redir' => { return auth_test() if auth_test();
"redir" => "index",
} unless vars->{"auth"};
my @domains = database->quick_select( my @domains = database->quick_select(
"domain", "domain",
@ -21,6 +21,8 @@ get '/domains' => sub {
}; };
post '/domains/new' => sub { post '/domains/new' => sub {
return auth_test() if auth_test();
my %errs; my %errs;
if (!param("name")) { if (!param("name")) {

18
lib/cyberman/Helper.pm Normal file
View File

@ -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;