CharmBoard/lib/CharmBoard.pm

179 lines
4.4 KiB
Perl
Raw Normal View History

package CharmBoard;
use utf8;
use strict;
use warnings;
use experimental qw(try);
use feature ':5.20';
use Mojo::Base 'Mojolicious', -signatures;
use CharmBoard::Model::Schema;
use CharmBoard::Util::Crypt::Seasoning;
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
# this method will run once at server start
sub startup {
my $self = shift;
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
# load plugins that require no additional conf
$self->plugin('TagHelpers');
$self->plugin('Model', {namespaces => ['CharmBoard::Model']});
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
# load configuration from config file
my $config =
$self->plugin('Config' => { file => 'charmboard.conf' });
# set this specific forum's name
$self->helper(board_name => sub { $config->{board_name} });
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
# load dev env only stuff, if applicable
if (lc($config->{environment}) eq 'dev') {
$self->renderer->cache->max_keys(0)
}
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
# import Mojolicious secrets
$self->secrets($config->{secrets});
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
# import password pepper value
$self->helper(pepper => sub { $config->{pass_crypt}->{pepper} });
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
## database setup
# ? this could maybe be a given/when
{
my ($_dsn, $_unicode);
if (lc($self->config->{database}->{type}) eq 'sqlite') {
$_dsn = "dbi:SQLite:" . $config->{database}->{name};
$_unicode = "sqlite_unicode"
} elsif (lc($self->config->{database}->{type}) eq '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::Model::Schema->connect(
$_dsn,
$config->{database}->{user},
$config->{database}->{pass},
{ $_unicode => 1 }
);
$self->helper(schema => sub { $schema })
}
# session helpers
## create session
$self->helper(session_create => sub {
my $self = shift;
my $_session_key = seasoning(16);
# create session entry in db
$self->schema->resultset('Session')->create({
session_key => $_session_key,
user_id => $_[0],
session_expiry => time + 604800,
is_ip_bound => 0,
bound_ip => undef
});
# now create session cookie
$self->session(is_auth => 1 );
$self->session(user_id => $_[0] );
$self->session(session_key => $_session_key);
$self->session(expiration => 604800 );
});
## destroy session
$self->helper(session_destroy => sub {
my $self = shift;
my $_session_key = $self->session('session_key');
# destroy entry for this session in the database
$self->schema->resultset('Session')
->search({ session_key => $_session_key })
->delete;
# now nuke the actual session cookie
$self->session(expires => 1);
});
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
# router
my $r = $self->routes;
2024-08-08 07:22:31 +00:00
# controller routes
## index page
$r->get('/')->to(
controller => 'Controller::Index',
action => 'index'
);
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
## registration page
$r->get('/register')->to(
controller => 'Controller::Register',
action => 'register'
);
$r->post('/register')->to(
controller => 'Controller::Register',
action => 'register_do'
);
Some prep for user sign in implementation + formatting changes global changes: - config now uses snake_case instead of camelCase for config entry names - closing brackets/braces never occur on their own line - there are almost never spaces inside brackets/braces before and after the actual content - I also removed a bunch of linebreaks I really shouldn't have because it just ended up worsening readability, so I'm going to put them back tomorrow lol `lib/CharmBoard.pm` : - removed PostgreSQL from the database driver detector, I just wanna stick with SQLite and MySQL initially since I'm only really familiar with those - detect dev environment (from conf file setting) and only shut caching off in that situation - removed the default layout config option `lib/CharmBoard/Crypt/Password.pm` - renamed subroutines from snake_case to whateverthisiscalled - changed what format `passgen` outputs salts and hashes in - changed size and factor for reasons I honestly don't remember at this point. I should probably recalibrate that properly tomorrow - added `passchk` subroutine for verifying of passwords on the login screen - nice and helpful comments `lib/CharmBoard/Crypt/Seasoning.pm` - this is what used to be `tools/pepper.pl`. it's not currently used for anything but it will be used for pepper generation during setup if CharmBoard ever gets to that point. also might use it for generating salts actually `lib/CharmBoard/Controller/Auth.pm` - realized I had the salt and hash variable assignments the wrong way 'round like an idiot, so I fixed that - added part of signup (password auth) - also lots of hopefully-helpful comments? `lib/CharmBoard/Schema/*.pm` - added more params for each column `lib/CharmBoard/Schema/Session.pm` - added `is_ip_bound` and `bound_ip` columns `database.sql` - as for stuff not mentioned in the schema module changes, I added `ON CONFLICT` behavior (it's all `ABORT`, which rolls back the entire transaction) i'm tired i'm spenfing too much time either reading about mojolicious/perl or actually programming in them (usually the former atm) i need to chillax and play some videogames
2023-05-07 06:04:15 +00:00
## login page
$r->get('/login')->to(
controller => 'Controller::Login',
action => 'login'
);
$r->post('/login')->to(
controller => 'Controller::Login',
action => 'login_do'
);
## logout
$r->get('/logout')->to(
controller => 'Controller::Logout',
action => 'logout_do'
);
# view subforum
$r->get('/board/:id')->to(
controller => 'Controller::ViewSubf',
action => 'subf_view'
);
# create thread
$r->get('/board/:id/new')->to(
controller => 'Controller::NewThread',
action => 'thread_compose'
);
$r->post('/board/:id/new')->to(
controller => 'Controller::NewThread',
action => 'thread_submit'
);
}
1;
__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 70 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
2024-08-21 04:34:54 +00:00
available today, inspired by older forum software like AcmlmBoard.
=cut