2023-05-06 04:24:49 +00:00
|
|
|
package CharmBoard;
|
2023-05-08 10:26:11 +00:00
|
|
|
use experimental 'try', 'smartmatch';
|
2023-05-06 04:24:49 +00:00
|
|
|
use Mojo::Base 'Mojolicious', -signatures;
|
|
|
|
use CharmBoard::Schema;
|
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# this method will run once at server start
|
2023-05-06 04:24:49 +00:00
|
|
|
sub startup ($app) {
|
2023-05-07 06:04:15 +00:00
|
|
|
# load plugins that require no additional conf
|
2023-05-06 04:24:49 +00:00
|
|
|
$app->plugin('TagHelpers');
|
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# load configuration from config file
|
|
|
|
my $config = $app->plugin('Config' => {file => 'charmboard.conf'});
|
2023-05-06 04:24:49 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# load dev env only stuff, if applicable
|
|
|
|
if ( $config->{environment} eq 'dev' ) {
|
|
|
|
$app->plugin('Renderer::WithoutCache');
|
|
|
|
$app->renderer->cache->max_keys(0)};
|
2023-05-06 04:24:49 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# import Mojolicious secrets
|
2023-05-06 04:24:49 +00:00
|
|
|
$app->secrets($config->{secrets});
|
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# import password pepper value
|
|
|
|
$app->helper(pepper => sub {$config->{pass_crypt}->{pepper}});
|
|
|
|
|
|
|
|
## database setup
|
|
|
|
my ($dsn, $dbUnicode);
|
2023-05-06 04:24:49 +00:00
|
|
|
if ($app->config->{database}->{type} ~~ 'sqlite') {
|
|
|
|
$dsn = "dbi:SQLite:" . $config->{database}->{name};
|
2023-05-07 06:04:15 +00:00
|
|
|
$dbUnicode = "sqlite_unicode"}
|
|
|
|
elsif ($app->config->{database}->{type} ~~ 'mysql') {
|
2023-05-06 04:24:49 +00:00
|
|
|
$dsn = "dbi:mysql:" . $config->{database}->{name};
|
2023-05-07 06:04:15 +00:00
|
|
|
$dbUnicode = "mysql_enable_utf"}
|
|
|
|
else {die "\nUnknown, unsupported, or empty database type in charmboard.conf.
|
2023-05-06 04:24:49 +00:00
|
|
|
If you're sure you've set it to something supported, maybe double check your spelling?\n
|
2023-05-07 06:04:15 +00:00
|
|
|
Valid options: 'sqlite', 'mysql'"};
|
2023-05-06 04:24:49 +00:00
|
|
|
my $schema = CharmBoard::Schema->connect(
|
|
|
|
$dsn,
|
|
|
|
$config->{database}->{user},
|
|
|
|
$config->{database}->{pass},
|
2023-05-07 06:04:15 +00:00
|
|
|
{$dbUnicode => 1});
|
|
|
|
$app->helper(schema => sub {$schema});
|
2023-05-06 04:24:49 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# router
|
2023-05-06 04:24:49 +00:00
|
|
|
my $r = $app->routes;
|
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# controller routes
|
|
|
|
## index page
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->get('/')->to(
|
|
|
|
controller => 'Controller::Main',
|
2023-05-07 06:04:15 +00:00
|
|
|
action => 'index');
|
|
|
|
## registration page
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->get('/register')->to(
|
|
|
|
controller => 'Controller::Auth',
|
2023-05-07 06:04:15 +00:00
|
|
|
action => 'register');
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->post('/register')->to(
|
|
|
|
controller => 'Controller::Auth',
|
2023-05-07 06:04:15 +00:00
|
|
|
action => 'register_do');
|
|
|
|
## login page
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->get('/login')->to(
|
|
|
|
controller => 'Controller::Auth',
|
2023-05-07 06:04:15 +00:00
|
|
|
action => 'login');
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->post('/login')->to(
|
|
|
|
controller => 'Controller::Auth',
|
2023-05-07 06:04:15 +00:00
|
|
|
action => 'login_do');
|
2023-05-06 04:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|