2023-05-06 04:24:49 +00:00
|
|
|
package CharmBoard;
|
2023-05-15 23:50:44 +00:00
|
|
|
|
2023-05-09 06:37:07 +00:00
|
|
|
use utf8;
|
2023-05-15 23:50:44 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use experimental qw(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-15 23:50:44 +00:00
|
|
|
sub startup {
|
|
|
|
my $self = shift;
|
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# load plugins that require no additional conf
|
2023-05-09 06:37:07 +00:00
|
|
|
$self->plugin('TagHelpers');
|
2023-05-15 23:50:44 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# load configuration from config file
|
2023-05-17 16:12:48 +00:00
|
|
|
my $config =
|
|
|
|
$self->plugin('Config' => { file => 'charmboard.conf' });
|
2023-05-09 06:37:07 +00:00
|
|
|
|
|
|
|
# set this specific forum's name
|
2023-05-17 16:12:48 +00:00
|
|
|
$self->helper(board_name => sub { $config->{board_name} });
|
2023-05-06 04:24:49 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# load dev env only stuff, if applicable
|
2023-05-17 04:18:25 +00:00
|
|
|
if ($config->{environment} eq 'dev') {
|
2023-05-17 16:12:48 +00:00
|
|
|
$self->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-09 06:37:07 +00:00
|
|
|
$self->secrets($config->{secrets});
|
2023-05-06 04:24:49 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# import password pepper value
|
2023-05-17 16:12:48 +00:00
|
|
|
$self->helper(pepper => sub { $config->{pass_crypt}->{pepper} });
|
2023-05-07 06:04:15 +00:00
|
|
|
|
|
|
|
## database setup
|
2023-05-09 06:37:07 +00:00
|
|
|
# ? this could maybe be a given/when
|
2023-05-17 16:12:48 +00:00
|
|
|
{
|
|
|
|
my ($_dsn, $_unicode);
|
2023-05-17 04:18:25 +00:00
|
|
|
if ($self->config->{database}->{type} ~~ 'sqlite') {
|
2023-05-17 16:12:48 +00:00
|
|
|
$_dsn = "dbi:SQLite:" . $config->{database}->{name};
|
|
|
|
$_unicode = "sqlite_unicode"
|
2023-05-17 04:18:25 +00:00
|
|
|
|
2023-05-17 16:12:48 +00:00
|
|
|
} elsif ($self->config->{database}->{type} ~~ 'mariadb') {
|
|
|
|
$_dsn = "dbi:mysql:" . $config->{database}->{name};
|
|
|
|
$_unicode = "mysql_enable_utf"
|
2023-05-17 04:18:25 +00:00
|
|
|
|
2023-05-17 16:12:48 +00:00
|
|
|
} else {
|
|
|
|
die "\nUnknown, unsupported, or empty database type
|
2023-05-17 04:18:25 +00:00
|
|
|
in charmboard.conf. If you're sure you've set it to
|
|
|
|
something supported, maybe double check your spelling?
|
|
|
|
\n\n\t
|
2023-05-17 16:12:48 +00:00
|
|
|
Valid options: 'sqlite', 'mariadb'"
|
|
|
|
}
|
2023-05-17 04:18:25 +00:00
|
|
|
|
|
|
|
our $schema = CharmBoard::Schema->connect(
|
|
|
|
$_dsn,
|
|
|
|
$config->{database}->{user},
|
|
|
|
$config->{database}->{pass},
|
2023-05-17 16:12:48 +00:00
|
|
|
{ $_unicode => 1 }
|
|
|
|
);
|
2023-05-17 04:18:25 +00:00
|
|
|
|
2023-05-17 16:12:48 +00:00
|
|
|
$self->helper(schema => sub { $schema })
|
|
|
|
}
|
2023-05-06 04:24:49 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# router
|
2023-05-09 06:37:07 +00:00
|
|
|
my $r = $self->routes;
|
2023-05-06 04:24:49 +00:00
|
|
|
|
2024-08-08 07:22:31 +00:00
|
|
|
# controller routes
|
|
|
|
## index page
|
|
|
|
$r->get('/')->to(
|
|
|
|
controller => 'Controller::Index',
|
|
|
|
action => 'index'
|
|
|
|
);
|
2023-05-17 04:18:25 +00:00
|
|
|
# view subforum
|
|
|
|
$r->get('/subforum/:id')->to(
|
|
|
|
controller => 'Controller::ViewSubf',
|
2023-05-17 16:12:48 +00:00
|
|
|
action => 'subf_view'
|
|
|
|
);
|
2023-05-17 04:18:25 +00:00
|
|
|
|
2024-08-08 07:22:31 +00:00
|
|
|
# create thread
|
|
|
|
$r->get('/thread/new/:id')->to(
|
|
|
|
controller => 'Controller::NewThread',
|
|
|
|
action => 'thread_compose'
|
|
|
|
);
|
|
|
|
$r->post('/thread/new/:id')->to(
|
|
|
|
controller => 'Controller::NewThread',
|
|
|
|
action => 'thread_submit'
|
2023-05-17 16:12:48 +00:00
|
|
|
);
|
2023-05-09 06:37:07 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
## registration page
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->get('/register')->to(
|
2023-05-09 06:37:07 +00:00
|
|
|
controller => 'Controller::Register',
|
2023-05-17 16:12:48 +00:00
|
|
|
action => 'register'
|
|
|
|
);
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->post('/register')->to(
|
2023-05-09 06:37:07 +00:00
|
|
|
controller => 'Controller::Register',
|
2023-05-17 16:12:48 +00:00
|
|
|
action => 'register_do'
|
|
|
|
);
|
2023-05-09 06:37:07 +00:00
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
## login page
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->get('/login')->to(
|
2023-05-09 06:37:07 +00:00
|
|
|
controller => 'Controller::Login',
|
2023-05-17 16:12:48 +00:00
|
|
|
action => 'login'
|
|
|
|
);
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->post('/login')->to(
|
2023-05-09 06:37:07 +00:00
|
|
|
controller => 'Controller::Login',
|
2023-05-17 16:12:48 +00:00
|
|
|
action => 'login_do'
|
|
|
|
);
|
2023-05-15 23:50:44 +00:00
|
|
|
|
2023-05-09 06:37:07 +00:00
|
|
|
## logout
|
|
|
|
$r->get('/logout')->to(
|
|
|
|
controller => 'Controller::Logout',
|
2023-05-17 16:12:48 +00:00
|
|
|
action => 'logout_do'
|
|
|
|
)
|
2023-05-06 04:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
2023-05-17 04:18:25 +00:00
|
|
|
__END__
|
|
|
|
|
|
|
|
=pod
|
|
|
|
=head1 NAME
|
|
|
|
CharmBoard - revive the fun posting experience!
|
|
|
|
|
|
|
|
=head1 NOTES
|
2023-05-17 16:12:48 +00:00
|
|
|
This documentation is intended for prospective code contributors. If
|
|
|
|
you're looking to set CharmBoard up, look for the Markdown format
|
|
|
|
(.md) documentation instead.
|
2023-05-17 04:18:25 +00:00
|
|
|
|
2023-05-17 16:12:48 +00:00
|
|
|
CharmBoard uses a max line length of 70 chars and a tab size of two
|
|
|
|
spaces.
|
2023-05-17 04:18:25 +00:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
2023-05-17 16:12:48 +00:00
|
|
|
CharmBoard is forum software written in Perl with Mojolicious,
|
|
|
|
intended to be a more fun alternative to the bigger forum suites
|
|
|
|
available today, inspired by older forum software like AcmlmBoard,
|
|
|
|
while also being more modernized in terms of security practices than
|
|
|
|
they are.
|
2023-05-17 04:18:25 +00:00
|
|
|
=cut
|