Create helper for checking if user is moderator

This commit is contained in:
swag 2022-11-28 23:55:11 -05:00
parent 45614f4035
commit de8a76271d
2 changed files with 10 additions and 3 deletions

View File

@ -50,6 +50,14 @@ sub startup($self) {
return $truncated_text; return $truncated_text;
}); });
$self->helper(is_mod => sub ($c) {
if (my $mod_id = $c->session->{'mod_id'}) {
return 1 if $mod_id =~ /\d/
}
return undef;
});
# Finish configuring some things # Finish configuring some things
$self->secrets($self->config->{'secrets'}) || die $@; $self->secrets($self->config->{'secrets'}) || die $@;
@ -135,7 +143,7 @@ sub startup($self) {
# Moderator # Moderator
my $moderator = $r->under('/moderator', sub ($c) { my $moderator = $r->under('/moderator', sub ($c) {
return 1 if $c->session('mod_id') =~ /^\d+$/; return 1 if $c->is_mod;
$c->redirect_to('mod_login'); $c->redirect_to('mod_login');
# Return false otherwise a body is rendered with the redirect... # Return false otherwise a body is rendered with the redirect...

View File

@ -8,8 +8,7 @@ sub login($self) {
my $v; my $v;
#Already logged in? #Already logged in?
return $self->redirect_to('mod_list') return $self->redirect_to('mod_list') if $self->is_mod;
if defined $self->session->{'mod_id'};
$v = $self->validation if $self->req->method eq 'POST'; $v = $self->validation if $self->req->method eq 'POST';