-
Guillaume ROUSSE authoredGuillaume ROUSSE authored
App.pm 2.86 KiB
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 => '1.2.0'
};
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' });
$self->plugin(
'TemplateToolkit',
{
name => 'tt2',
template => {
ABSOLUTE => 1,
ENCODING => 'utf8',
PRE_CHOMP => CHOMP_ONE,
PLUGIN_BASE => 'AccessCheck::Template::Plugin',
}
}
);
$self->plugin('ClientIP');
my $config = $self->config();
$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 => [ $self->string_to_list($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'),