Clean up routing

This commit is contained in:
swagg boi 2023-04-24 12:14:04 -04:00
parent 777a8fbcda
commit 8cfd13d821
2 changed files with 21 additions and 17 deletions

View file

@ -97,7 +97,7 @@ sub startup($self) {
$r->get('/', sub ($c) { $c->redirect_to('threads_list') }); $r->get('/', sub ($c) { $c->redirect_to('threads_list') });
# Thread # Thread
my $thread = $r->under('/thread'); my $thread = $r->any('/thread');
$thread->get('/list/:list_page', [list_page => qr/\d+/], {list_page => 1}) $thread->get('/list/:list_page', [list_page => qr/\d+/], {list_page => 1})
->to('thread#by_page') ->to('thread#by_page')
@ -107,7 +107,7 @@ sub startup($self) {
->to('thread#create') ->to('thread#create')
->name('post_thread'); ->name('post_thread');
$thread->under('/single/:thread_id', [thread_id => qr/\d+/]) $thread->any('/single/:thread_id', [thread_id => qr/\d+/])
->get('/:thread_page', [thread_page => qr/\d+/], {thread_page => 1}) ->get('/:thread_page', [thread_page => qr/\d+/], {thread_page => 1})
->to('thread#by_id') ->to('thread#by_id')
->name('single_thread'); ->name('single_thread');
@ -121,7 +121,7 @@ sub startup($self) {
->name('flag_thread'); ->name('flag_thread');
# Remark # Remark
my $remark = $r->under('/remark'); my $remark = $r->any('/remark');
$remark->any([qw{GET POST}], '/post/:thread_id', [thread_id => qr/\d+/]) $remark->any([qw{GET POST}], '/post/:thread_id', [thread_id => qr/\d+/])
->to('remark#create') ->to('remark#create')
@ -145,12 +145,7 @@ sub startup($self) {
->name('mod_logout'); ->name('mod_logout');
# Moderator # Moderator
my $moderator = $r->under('/moderator', sub ($c) { my $moderator = $r->under('/moderator')->to('moderator#check');
return 1 if $c->is_mod;
# Return undef otherwise a body is rendered with the redirect...
return $c->redirect_to('mod_login'), undef;
});
$moderator->get('/flagged') $moderator->get('/flagged')
->to('moderator#flagged') ->to('moderator#flagged')
@ -164,7 +159,7 @@ sub startup($self) {
->to('moderator#mod_reset') ->to('moderator#mod_reset')
->name('mod_reset'); ->name('mod_reset');
my $mod_thread = $moderator->under('/thread'); my $mod_thread = $moderator->any('/thread');
$mod_thread->get('/unflag/:thread_id', [thread_id => qr/\d+/]) $mod_thread->get('/unflag/:thread_id', [thread_id => qr/\d+/])
->to('moderator#unflag_thread') ->to('moderator#unflag_thread')
@ -178,7 +173,7 @@ sub startup($self) {
->to('moderator#unhide_thread') ->to('moderator#unhide_thread')
->name('unhide_thread'); ->name('unhide_thread');
my $mod_remark = $moderator->under('/remark'); my $mod_remark = $moderator->any('/remark');
$mod_remark->get('/unflag/:remark_id', [remark_id => qr/\d+/]) $mod_remark->get('/unflag/:remark_id', [remark_id => qr/\d+/])
->to('moderator#unflag_remark') ->to('moderator#unflag_remark')
@ -192,12 +187,8 @@ sub startup($self) {
->to('moderator#unhide_remark') ->to('moderator#unhide_remark')
->name('unhide_remark'); ->name('unhide_remark');
my $mod_admin = $moderator->under('/admin', sub ($c) { # Admin
return 1 if $c->is_admin; my $mod_admin = $moderator->under('/admin')->to('moderator#admin_check');
# Return undef otherwise a body is rendered with the redirect...
return $c->redirect_to('mod_login'), undef;
});
$mod_admin->any([qw{GET POST}], '/create') $mod_admin->any([qw{GET POST}], '/create')
->to('moderator#create') ->to('moderator#create')

View file

@ -321,4 +321,17 @@ sub demote($self) {
return $self->render; return $self->render;
} }
sub check($self) {
return 1 if $self->is_mod;
# Return undef otherwise body is rendered with redirect
return $self->redirect_to('mod_login'), undef;
}
sub admin_check($self) {
return 1 if $self->is_admin;
return $self->redirect_to('mod_login'), undef;
}
1; 1;