-
-
Save jberger/c69599f61c67b6149af8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package LegendApp; | |
use Mojo::Base 'Mojolicious'; | |
use experimental qw/signatures postderef/; | |
use DBM::Deep; | |
use LegendApp::Artwork; | |
has db => sub { DBM::Deep->new('legend.db') }; | |
has artwork => sub { LegendApp::Artwork->new(shift->home->rel_dir('artwork')) }; | |
sub startup ($app) { | |
my $r = $app->routes; | |
$r->add_shortcut(authorized => sub ($r, @) { | |
return $r->under(sub ($c) { | |
return $c->redirect_to('login') unless $c->session('username'); | |
return 1; | |
}); | |
}); | |
# a few admin tasks are without authorization | |
my $admin = $r->any('/admin'); | |
$admin->any('/login')->name('login')->to('admin#') | |
->tap(get => { template => 'admin/login' }) | |
->tap(post => { action => 'login' }); | |
$admin->any('/logout')->to('admin#logout'); | |
# all others are | |
$admin = $admin->authorized; | |
$admin->any('/files')->name('files') | |
->tap(get => { template => 'admin/files' }) | |
->tap(post => { action => 'upload_files' }) | |
->tap(delete => { action => 'delete_files' }); | |
$r->any('/:name', {name => 1}) | |
->to('page#') | |
->name('page') | |
->tap(get => { action => 'get' }) | |
->authorized | |
->tap(put => { action => 'create' }) | |
->tap(patch => { action => 'update' }) | |
->tap(delete => { action => 'delete' }); | |
} | |
1; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment