package AccessCheck::App; use Mojo::Base qw(Mojolicious); use English qw(-no_match_vars); use Template::Constants qw(:chomp); use Syntax::Keyword::Try; use AccessCheck::Data::DB; use constant { ACCESSCHECK_VERSION => '2.0.3' }; sub startup { my $self = shift; $self->helper( string_to_list => sub { my $self = shift; my $value = shift; return defined $value ? split(/, */, $value) : (); } ); $self->plugin('INIConfig', { file => $ENV{ACCESS_CHECK_CONFIG} || 'conf/manager.conf' }); my $config = $self->config(); $self->plugin( 'TemplateToolkit', { name => 'tt2', template => { ABSOLUTE => 1, ENCODING => 'utf8', PRE_CHOMP => CHOMP_ONE, PLUGIN_BASE => 'AccessCheck::Template::Plugin', } } ); $self->plugin( 'ForwardedFor', ); $self->log( Mojo::Log->new( path => $config->{logger}->{file}, level => ($config->{logger}->{level} || 'trace') ) ); AccessCheck::Data::DB->register_db( driver => $config->{database}->{type}, database => $config->{database}->{name}, host => $config->{database}->{host}, password => $config->{database}->{password}, username => $config->{database}->{username}, options => $config->{database}->{options} ); my $theme = $config->{setup}->{templates_theme} || 'default'; my $base_templates_dir = $self->home()->child('templates'); my $renderer = $self->renderer(); $renderer->default_handler('tt2'); $renderer->paths([ $base_templates_dir->child('web', $theme), $base_templates_dir->child('web'), $base_templates_dir->child('accounts'), $base_templates_dir->child('other'), ]); $self->defaults( app => { support_url => $config->{app}->{support_url}, support_email => $config->{app}->{support_email}, login_url => $config->{app}->{login_url}, logout_url => $config->{app}->{logout_url}, name => $config->{app}->{name}, version => ACCESSCHECK_VERSION }, ); my $routes = $self->routes(); $routes->get('/')->to(controller => 'home', action => 'run')->name('home'); $routes->get('/status')->to(controller => 'status', action => 'run')->name('status'); $routes->get('/step1')->to(controller => 'step1', action => 'run')->name('step1'); $routes->get('/step2')->to(controller => 'step2', action => 'run')->name('step2'); $routes->get('/step3')->to(controller => 'step3', action => 'run')->name('step3'); $routes->get('/step4')->to(controller => 'step4', action => 'run')->name('step4'); $routes->get('/step5')->to(controller => 'step5', action => 'run')->name('step5'); } 1;