From 4eec3f79c5619916fc37b6346a9fcca7f04f8ad8 Mon Sep 17 00:00:00 2001 From: ngoomie Date: Sat, 13 May 2023 17:49:55 -0600 Subject: [PATCH] Largely just add POD doc --- .vscode/settings.json | 4 +- lib/CharmBoard.pm | 1 + lib/CharmBoard/Controller/Login.pm | 3 +- lib/CharmBoard/Controller/Logout.pm | 2 +- lib/CharmBoard/Controller/Register.pm | 8 ++-- lib/CharmBoard/Crypt/Password.pm | 52 +++++++++++++--------- lib/CharmBoard/Schema/Source/Categories.pm | 37 +++++++++++++++ lib/CharmBoard/Schema/Source/Posts.pm | 47 +++++++++++++++++++ lib/CharmBoard/Schema/Source/Session.pm | 2 +- lib/CharmBoard/Schema/Source/Subforums.pm | 46 +++++++++++++++++++ lib/CharmBoard/Schema/Source/Threads.pm | 32 +++++++++++-- lib/CharmBoard/Schema/Source/Users.pm | 46 +++++++++++++++++++ 12 files changed, 247 insertions(+), 33 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5ed3be2..3b02443 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,9 +12,11 @@ "passgen", "resultset", "signup", + "SMALLINT", "subf", "subforum", - "subforums" + "subforums", + "TINYTEXT" ], "better-comments.highlightPlainText": true, "better-comments.tags": [ diff --git a/lib/CharmBoard.pm b/lib/CharmBoard.pm index c32d7ac..cc26438 100644 --- a/lib/CharmBoard.pm +++ b/lib/CharmBoard.pm @@ -5,6 +5,7 @@ use Mojo::Base 'Mojolicious', -signatures; use CharmBoard::Schema; =pod +=encoding utf8 =head1 NAME CharmBoard - revive the fun posting experience! =head1 NOTES diff --git a/lib/CharmBoard/Controller/Login.pm b/lib/CharmBoard/Controller/Login.pm index acadd5f..49434e8 100644 --- a/lib/CharmBoard/Controller/Login.pm +++ b/lib/CharmBoard/Controller/Login.pm @@ -6,6 +6,7 @@ use CharmBoard::Crypt::Password; use CharmBoard::Crypt::Seasoning; =pod +=encoding utf8 =head1 NAME CharmBoard::Controller::Login =cut @@ -28,7 +29,7 @@ sub login_do ($self) { try { # check user credentials first # check to see if user by entered username exists - $userInfo = $self->schema->resultset('Users')->search( + $userInfo = $self->schema->resultset('Users')->find( {username => $username}); $userInfo or die; diff --git a/lib/CharmBoard/Controller/Logout.pm b/lib/CharmBoard/Controller/Logout.pm index aa6084a..a4f830c 100644 --- a/lib/CharmBoard/Controller/Logout.pm +++ b/lib/CharmBoard/Controller/Logout.pm @@ -5,7 +5,7 @@ use Mojo::Base 'Mojolicious::Controller', -signatures; sub logout_do ($self) { # destroy entry for this session in the database - $self->schema->resultset('Session')->search({ + $self->schema->resultset('Session')->find({ session_key => $self->session('session_key')})->delete; # now nuke the actual session cookie $self->session(expires => 1); diff --git a/lib/CharmBoard/Controller/Register.pm b/lib/CharmBoard/Controller/Register.pm index 3fdab24..0efe3a9 100644 --- a/lib/CharmBoard/Controller/Register.pm +++ b/lib/CharmBoard/Controller/Register.pm @@ -39,10 +39,10 @@ sub register_do ($self) { # check to make sure username and/or email isn't already in use; # if not, continue with registration ## search for input username and email in database - $userCheck = $self->schema->resultset('Users')->search( - {username => $username})->single; - $emailCheck = $self->schema->resultset('Users')->search( - {email => $email})->single; + $userCheck = $self->schema->resultset('Users')->find( + {username => $username}); + $emailCheck = $self->schema->resultset('Users')->find( + {email => $email}); ($userCheck && $emailCheck) eq undef or die "Username already in use.\nemail already in use."; diff --git a/lib/CharmBoard/Crypt/Password.pm b/lib/CharmBoard/Crypt/Password.pm index daa3b9a..31ccfb7 100644 --- a/lib/CharmBoard/Crypt/Password.pm +++ b/lib/CharmBoard/Crypt/Password.pm @@ -7,30 +7,37 @@ use Exporter qw(import); our @EXPORT = qw(passgen passchk); =pod +=encoding utf8 =head1 NAME CharmBoard::Crypt::Password - password processing module =head1 SYNOPSIS =begin perl use CharmBoard::Crypt::Password; -($salt, $hash) = passgen($plaintextPassword); -$passwordVerification = passchk($salt, $hash, $plaintextPassword) +my ($salt, $hash) = + passgen($plaintextPassword); + +$passwordVerification = + passchk($salt, $hash, $plaintextPassword) =end perl =head1 DESCRIPTION -CharmBoard::Crypt::Password processes passwords, either processing -new passwords for database storage, or checking passwords entered -when logging in to make sure they're correct. +CharmBoard::Crypt::Password processes passwords, either +processing new passwords for database storage, or checking +passwords entered when logging in to make sure they're +correct. -Currently the only available password hashing scheme is Argon2, but -this might be changed later on. +Currently the only available password hashing scheme is +Argon2, but this might be changed later on. +=over =cut =pod -=head2 passgen -passgen is the function for generating password salts and hashes to -be inserted into the database. It takes the plaintext password you -wish to hash as the only argument, and outputs the salt and -Argon2 hash string in hexadecimal form. +=item passgen +passgen is the function for generating password salts and +hashes to be inserted into the database. It takes the +plaintext password you wish to hash as the only argument, +and outputs the salt and Argon2 hash string in hexadecimal +form. =cut sub passgen ($) { my $argon2 = Authen::Passphrase::Argon2->new( @@ -44,15 +51,18 @@ sub passgen ($) { return ($argon2->salt_hex, $argon2->hash_hex)}; =pod -=head2 passchk -passchk is the function for checking plaintext passwords against the -hashed password + salt already stored in the database. It takes the -salt and Argon2 hash string in hex form plus the plaintext password -as inputs, and outputs a true/false value indicating whether or not -the input password matched. Intended for login authentication or -anywhere else where one may need to verify passwords (i.e. before -changing existing passwords, or for admins confirming they wish to -perform a risky or nonreversible operation.) +=item passchk +passchk is the function for checking plaintext passwords +against the hashed password + salt already stored in the +database. It takes the salt and Argon2 hash string in hex +form plus the plaintext password as inputs, and outputs a +true/false value indicating whether or not the input +password matched. Intended for login authentication or +anywhere else where one may need to verify passwords (i.e. +before changing existing passwords, or for admins +confirming they wish to perform a risky or nonreversible +operation.) +=back =cut sub passchk ($$$) { my $argon2 = Authen::Passphrase::Argon2->new( diff --git a/lib/CharmBoard/Schema/Source/Categories.pm b/lib/CharmBoard/Schema/Source/Categories.pm index fc4213d..cae0380 100644 --- a/lib/CharmBoard/Schema/Source/Categories.pm +++ b/lib/CharmBoard/Schema/Source/Categories.pm @@ -1,14 +1,51 @@ package CharmBoard::Schema::Source::Categories; use base qw(DBIx::Class::Core); +=pod +=encoding utf8 +=head1 NAME +CharmBoard::Schema::Source::Categories - DBIx::Class +ResultSource module for the database's C table +=head1 DESCRIPTION +This table contains info about categories, which are used +solely to organize subforums on places like the index page. +=head2 Columns +=over +=item cat_id +Contains unique IDs for individual categories. + +Data type is SQLite C; MariaDB C. +Cannot be C. + +=item cat_rank +The order in which categories should be displayed. + +Data type is SQLite C; MariaDB C. +Cannot be C. + +=item cat_name +The name of the category to be displayed in the forum list. + +Data type is SQLite C; MariaDB C. +Cannot be C. +=back +=cut + __PACKAGE__->table('categories'); __PACKAGE__->add_columns( + cat_id => { data_type => 'integer', + is_numeric => 1, is_auto_increment => 1, is_nullable => 0, }, + cat_rank => { + data_type => 'integer', + is_auto_increment => 0, + is_nullable => 0, }, cat_name => { data_type => 'text', + is_auto_increment => 0, is_nullable => 0, }); __PACKAGE__->set_primary_key('cat_id'); diff --git a/lib/CharmBoard/Schema/Source/Posts.pm b/lib/CharmBoard/Schema/Source/Posts.pm index 55a0398..c6a7cc6 100644 --- a/lib/CharmBoard/Schema/Source/Posts.pm +++ b/lib/CharmBoard/Schema/Source/Posts.pm @@ -1,6 +1,48 @@ package CharmBoard::Schema::Source::Posts; use base qw(DBIx::Class::Core); +=pod +=encoding utf8 +=head1 NAME +CharmBoard::Schema::Source::Posts - DBIx::Class +ResultSource module for the database's C table +=head1 DESCRIPTION +This table contains post content and other important post +information (such as post date). +=head2 Columns +=over +=item post_id +Contains unique IDs for posts. + +Data type is SQLite C; MariaDB C. Cannot +be C. + +=item user_id +Contains the user ID of the creator of a given post. + +Is foreign key of C, and as such, shares the +same datatype (SQLite C; MariaDB C). +Cannot be C. + +=item thread_id +Contains the ID of the thread this post was posted in. + +Is foreign key of C, and as such, shares +the same datatype (C in SQLite). Cannot be C. + +=item post_date +Contains the date the post was made, in the format provided +by Perl's C