Use perlcritic theme; add is_admin() helper; clean up some things

This commit is contained in:
swag 2022-12-18 14:00:54 -05:00
parent 4527219d91
commit 5cce06c984
4 changed files with 24 additions and 4 deletions

View File

@ -1 +1 @@
exclude = Subroutines::ProhibitSubroutinePrototypes theme = community

View File

@ -4,3 +4,4 @@ requires 'Mojolicious::Plugin::TagHelpers::Pagination';
requires 'Mojolicious::Plugin::AssetPack'; requires 'Mojolicious::Plugin::AssetPack';
requires 'Crypt::Passphrase::Argon2'; requires 'Crypt::Passphrase::Argon2';
requires 'Crypt::Passphrase::Bcrypt'; # Needed for old passphrases requires 'Crypt::Passphrase::Bcrypt'; # Needed for old passphrases
requires 'Perl::Critic::Community';

View File

@ -58,6 +58,14 @@ sub startup($self) {
return undef; return undef;
}); });
$self->helper(is_admin => sub ($c) {
if (my $admin_id = $c->session->{'admin_id'}) {
return 1 if $admin_id =~ /\d+/
}
return undef;
});
# Finish configuring some things # Finish configuring some things
$self->secrets($self->config->{'secrets'}) || die $@; $self->secrets($self->config->{'secrets'}) || die $@;
@ -144,7 +152,7 @@ sub startup($self) {
my $moderator = $r->under('/moderator', sub ($c) { my $moderator = $r->under('/moderator', sub ($c) {
return 1 if $c->is_mod; return 1 if $c->is_mod;
# Return false otherwise a body is rendered with the redirect... # Return undef otherwise a body is rendered with the redirect...
return $c->redirect_to('mod_login'), undef; return $c->redirect_to('mod_login'), undef;
}); });
@ -183,6 +191,15 @@ sub startup($self) {
$mod_remark->get('/unhide/:remark_id', [remark_id => qr/\d+/]) $mod_remark->get('/unhide/:remark_id', [remark_id => qr/\d+/])
->to('moderator#unhide_remark') ->to('moderator#unhide_remark')
->name('unhide_remark'); ->name('unhide_remark');
my $admin = $moderator->under('/admin', sub ($c) {
return 1 if $c->is_admin;
# Return undef otherwise a body is rendered with the redirect...
return $c->recirect_to('mod_login'), undef;
});
# Actions to create mods...
} }
1; 1;

View File

@ -1,2 +1,4 @@
ALTER TABLE moderators ALTER TABLE moderators
ADD admin_status BOOLEAN NOT NULL DEFAULT FALSE; ADD admin_status BOOLEAN
NOT NULL
DEFAULT FALSE;