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-09 06:37:07 +00:00
|
|
|
my $config = $self->plugin('Config' =>
|
|
|
|
{file => 'charmboard.conf'});
|
|
|
|
|
|
|
|
# set this specific forum's name
|
2023-05-17 04:18:25 +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-09 06:37:07 +00:00
|
|
|
$self->plugin('Renderer::WithoutCache');
|
|
|
|
$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 04:18:25 +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 04:18:25 +00:00
|
|
|
{ my ($_dsn, $_unicode);
|
|
|
|
if ($self->config->{database}->{type} ~~ 'sqlite') {
|
|
|
|
$_dsn = "dbi:SQLite:" . $config->{database}->{name};
|
|
|
|
$_unicode = "sqlite_unicode"}
|
|
|
|
|
|
|
|
elsif ($self->config->{database}->{type} ~~ 'mariadb') {
|
|
|
|
$_dsn = "dbi:mysql:" . $config->{database}->{name};
|
|
|
|
$_unicode = "mysql_enable_utf"}
|
|
|
|
|
|
|
|
else {die "\nUnknown, unsupported, or empty database type
|
|
|
|
in charmboard.conf. If you're sure you've set it to
|
|
|
|
something supported, maybe double check your spelling?
|
|
|
|
\n\n\t
|
|
|
|
Valid options: 'sqlite', 'mariadb'"};
|
|
|
|
|
|
|
|
our $schema = CharmBoard::Schema->connect(
|
|
|
|
$_dsn,
|
|
|
|
$config->{database}->{user},
|
|
|
|
$config->{database}->{pass},
|
|
|
|
{$_unicode => 1});
|
|
|
|
|
|
|
|
$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
|
|
|
|
2023-05-17 04:18:25 +00:00
|
|
|
# view subforum
|
|
|
|
$r->get('/subforum/:id')->to(
|
|
|
|
controller => 'Controller::ViewSubf',
|
|
|
|
action => 'subf_view');
|
|
|
|
|
2023-05-07 06:04:15 +00:00
|
|
|
# controller routes
|
|
|
|
## index page
|
2023-05-06 04:24:49 +00:00
|
|
|
$r->get('/')->to(
|
2023-05-09 06:37:07 +00:00
|
|
|
controller => 'Controller::Index',
|
2023-05-07 06:04:15 +00:00
|
|
|
action => 'index');
|
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-07 06:04:15 +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-07 06:04:15 +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-07 06:04:15 +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-07 06:04:15 +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',
|
|
|
|
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
|
|
|
|
This documentation is intended for prospective code
|
|
|
|
contributors. If you're looking to set CharmBoard up,
|
|
|
|
look for the Markdown format (.md) documentation instead.
|
|
|
|
|
|
|
|
CharmBoard uses a max line length of 60 chars and a tab
|
|
|
|
size of two spaces.
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
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.
|
|
|
|
=cut
|