From 45343a87fd9d5ac6be0f10098335a40c18151de2 Mon Sep 17 00:00:00 2001 From: ngoomie Date: Tue, 16 May 2023 08:29:05 -0600 Subject: [PATCH] Fix category and subforum listing on index + misc --- lib/CharmBoard/Controller/Index.pm | 14 +++++++------- lib/CharmBoard/Controller/Login.pm | 12 +++++++----- lib/CharmBoard/Controller/Logout.pm | 6 ++++-- lib/CharmBoard/Controller/Register.pm | 10 ++++++---- lib/CharmBoard/Crypt/Password.pm | 6 ++++-- lib/CharmBoard/Crypt/Seasoning.pm | 6 ++++-- lib/CharmBoard/Schema.pm | 4 +++- lib/CharmBoard/Schema/Set/Categories.pm | 1 - lib/CharmBoard/Schema/Set/Subforums.pm | 4 +--- lib/CharmBoard/Schema/Source/Categories.pm | 6 ++++-- lib/CharmBoard/Schema/Source/Posts.pm | 4 +++- lib/CharmBoard/Schema/Source/Session.pm | 6 ++++-- lib/CharmBoard/Schema/Source/Subforums.pm | 4 +++- lib/CharmBoard/Schema/Source/Threads.pm | 4 +++- lib/CharmBoard/Schema/Source/Users.pm | 4 +++- script/CharmBoard | 5 +++-- templates/index.html.ep | 1 + 17 files changed, 60 insertions(+), 37 deletions(-) diff --git a/lib/CharmBoard/Controller/Index.pm b/lib/CharmBoard/Controller/Index.pm index f864d68..5e74458 100644 --- a/lib/CharmBoard/Controller/Index.pm +++ b/lib/CharmBoard/Controller/Index.pm @@ -3,7 +3,6 @@ package CharmBoard::Controller::Index; use utf8; use strict; use warnings; -use feature qw(say unicode_strings); use experimental qw(try smartmatch); use Mojo::Base 'Mojolicious::Controller', -signatures; @@ -19,27 +18,28 @@ sub index { # create a Tree::Simple object that will contain the list # of categories and the subforums that belong to them my $tree = - Tree::Simple->new("subfList", Tree::Simple->ROOT); + Tree::Simple->new("ROOT", Tree::Simple->ROOT); - my ($fetchSubf, $catBranch); + my (@fetchSubf, $catBranch); foreach my $iterCat (@allCat) { - # create branch of subfList for the current category + # create branch of ROOT for the current category + $catBranch = Tree::Simple->new($iterCat, $tree); # fetch all subforums that belong to this category - $fetchSubf = + @fetchSubf = $self->schema->resultset('Subforums') ->fetch_by_cat($iterCat); # add each fetched subforum as children of the branch # for the current category - foreach my $iterSubf ($fetchSubf) { + foreach my $iterSubf (@fetchSubf) { Tree::Simple->new($iterSubf, $catBranch)}} $self->render( template => 'index', - categoryTree => $tree)} + categoryTree => $tree)} 1; __END__ \ No newline at end of file diff --git a/lib/CharmBoard/Controller/Login.pm b/lib/CharmBoard/Controller/Login.pm index 3305cc5..c9ecdbf 100644 --- a/lib/CharmBoard/Controller/Login.pm +++ b/lib/CharmBoard/Controller/Login.pm @@ -1,15 +1,17 @@ package CharmBoard::Controller::Login; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use Mojo::Base 'Mojolicious::Controller', -signatures; use CharmBoard::Crypt::Password; use CharmBoard::Crypt::Seasoning; sub login { my $self = shift; - + $self->render( template => 'login', error => $self->flash('error'), @@ -56,16 +58,16 @@ sub login_do { session_expiry => time + 604800, is_ip_bound => 0, bound_ip => undef }) or die; - + # now create session cookie for user $self->session(is_auth => 1); $self->session(user_id => $userID); $self->session(session_key => $sessionKey); $self->session(expiration => 604800); - + # redirect to index upon success $self->redirect_to('/')} - + catch ($catchError) { # redirect to login page on fail print $catchError; $self->flash(error => 'Your username and password were correct, diff --git a/lib/CharmBoard/Controller/Logout.pm b/lib/CharmBoard/Controller/Logout.pm index 9e20740..fd0e9ab 100644 --- a/lib/CharmBoard/Controller/Logout.pm +++ b/lib/CharmBoard/Controller/Logout.pm @@ -1,13 +1,15 @@ package CharmBoard::Controller::Logout; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use Mojo::Base 'Mojolicious::Controller', -signatures; sub logout_do { my $self = shift; - + # destroy entry for this session in the database $self->schema->resultset('Session')->search({ session_key => $self->session('session_key')})->delete; diff --git a/lib/CharmBoard/Controller/Register.pm b/lib/CharmBoard/Controller/Register.pm index 2329412..9a74647 100644 --- a/lib/CharmBoard/Controller/Register.pm +++ b/lib/CharmBoard/Controller/Register.pm @@ -1,13 +1,15 @@ package CharmBoard::Controller::Register; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use Mojo::Base 'Mojolicious::Controller', -signatures; use CharmBoard::Crypt::Password; # initial registration page -sub register { +sub register { my $self = shift; $self->render( template => 'register', @@ -15,9 +17,9 @@ sub register { message => $self->flash('message'))}; # process submitted registration form -sub register_do { +sub register_do { my $self = shift; - + my $username = $self->param('username'); my $email = $self->param('email'); my $password = $self->param('password'); diff --git a/lib/CharmBoard/Crypt/Password.pm b/lib/CharmBoard/Crypt/Password.pm index f70119c..a536499 100644 --- a/lib/CharmBoard/Crypt/Password.pm +++ b/lib/CharmBoard/Crypt/Password.pm @@ -1,8 +1,10 @@ package CharmBoard::Crypt::Password; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use Authen::Passphrase::Argon2; use CharmBoard::Crypt::Seasoning; @@ -16,7 +18,7 @@ sub passgen { cost => 17, factor => '32M', parallelism => 1, - size => 32 ); + size => 32 ); return ($argon2->salt_hex, $argon2->hash_hex)}; diff --git a/lib/CharmBoard/Crypt/Seasoning.pm b/lib/CharmBoard/Crypt/Seasoning.pm index fcf79df..8a41380 100644 --- a/lib/CharmBoard/Crypt/Seasoning.pm +++ b/lib/CharmBoard/Crypt/Seasoning.pm @@ -1,8 +1,10 @@ package CharmBoard::Crypt::Seasoning; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use Math::Random::Secure qw(irand); use Exporter qw(import); @@ -18,7 +20,7 @@ sub seasoning { while (length($blend) < $_[0]) { # gen num to choose char for $blend $blend = $blend . $spices[irand(@spices)]}; - + return ($blend); } 1; \ No newline at end of file diff --git a/lib/CharmBoard/Schema.pm b/lib/CharmBoard/Schema.pm index 29868bf..daef417 100644 --- a/lib/CharmBoard/Schema.pm +++ b/lib/CharmBoard/Schema.pm @@ -1,8 +1,10 @@ package CharmBoard::Schema; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use base qw(DBIx::Class::Schema); __PACKAGE__->load_namespaces( diff --git a/lib/CharmBoard/Schema/Set/Categories.pm b/lib/CharmBoard/Schema/Set/Categories.pm index e9f8911..e5623b6 100644 --- a/lib/CharmBoard/Schema/Set/Categories.pm +++ b/lib/CharmBoard/Schema/Set/Categories.pm @@ -3,7 +3,6 @@ package CharmBoard::Schema::Set::Categories; use utf8; use strict; use warnings; -use feature qw(say unicode_strings); use experimental qw(try smartmatch); use base 'DBIx::Class::ResultSet'; diff --git a/lib/CharmBoard/Schema/Set/Subforums.pm b/lib/CharmBoard/Schema/Set/Subforums.pm index f6a895e..a253704 100644 --- a/lib/CharmBoard/Schema/Set/Subforums.pm +++ b/lib/CharmBoard/Schema/Set/Subforums.pm @@ -3,7 +3,6 @@ package CharmBoard::Schema::Set::Subforums; use utf8; use strict; use warnings; -use feature qw(say unicode_strings); use experimental qw(try smartmatch); use base 'DBIx::Class::ResultSet'; @@ -14,8 +13,7 @@ sub fetch_by_cat { my $fetch = $set->search( {'subf_cat' => $_[0] }, - {order_by => 'subf_rank', - group_by => undef}); + {order_by => 'subf_rank'}); return($fetch->get_column('subf_id')->all)} diff --git a/lib/CharmBoard/Schema/Source/Categories.pm b/lib/CharmBoard/Schema/Source/Categories.pm index d57ffe5..5b2a3ef 100644 --- a/lib/CharmBoard/Schema/Source/Categories.pm +++ b/lib/CharmBoard/Schema/Source/Categories.pm @@ -1,8 +1,10 @@ package CharmBoard::Schema::Source::Categories; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use base qw(DBIx::Class::Core); __PACKAGE__->table('categories'); @@ -17,7 +19,7 @@ __PACKAGE__->add_columns( cat_name => { data_type => 'text', is_nullable => 0, }); - + __PACKAGE__->set_primary_key('cat_id'); 1; diff --git a/lib/CharmBoard/Schema/Source/Posts.pm b/lib/CharmBoard/Schema/Source/Posts.pm index 8e82b16..fba636e 100644 --- a/lib/CharmBoard/Schema/Source/Posts.pm +++ b/lib/CharmBoard/Schema/Source/Posts.pm @@ -1,8 +1,10 @@ package CharmBoard::Schema::Source::Posts; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use base qw(DBIx::Class::Core); __PACKAGE__->table('posts'); diff --git a/lib/CharmBoard/Schema/Source/Session.pm b/lib/CharmBoard/Schema/Source/Session.pm index caa32de..99a6475 100644 --- a/lib/CharmBoard/Schema/Source/Session.pm +++ b/lib/CharmBoard/Schema/Source/Session.pm @@ -1,8 +1,10 @@ package CharmBoard::Schema::Source::Session; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use base qw(DBIx::Class::Core); __PACKAGE__->table('sessions'); @@ -22,7 +24,7 @@ __PACKAGE__->add_columns( bound_ip => { data_type => 'text', is_nullable => 1, }); - + __PACKAGE__->set_primary_key('session_key'); __PACKAGE__->belongs_to( diff --git a/lib/CharmBoard/Schema/Source/Subforums.pm b/lib/CharmBoard/Schema/Source/Subforums.pm index bbefc63..77b9b80 100644 --- a/lib/CharmBoard/Schema/Source/Subforums.pm +++ b/lib/CharmBoard/Schema/Source/Subforums.pm @@ -1,8 +1,10 @@ package CharmBoard::Schema::Source::Subforums; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use base qw(DBIx::Class::Core); __PACKAGE__->table('subforums'); diff --git a/lib/CharmBoard/Schema/Source/Threads.pm b/lib/CharmBoard/Schema/Source/Threads.pm index 85d521a..de5d590 100644 --- a/lib/CharmBoard/Schema/Source/Threads.pm +++ b/lib/CharmBoard/Schema/Source/Threads.pm @@ -1,8 +1,10 @@ package CharmBoard::Schema::Source::Threads; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use base qw(DBIx::Class::Core); __PACKAGE__->table('threads'); diff --git a/lib/CharmBoard/Schema/Source/Users.pm b/lib/CharmBoard/Schema/Source/Users.pm index 81ab6b3..82c2ed7 100644 --- a/lib/CharmBoard/Schema/Source/Users.pm +++ b/lib/CharmBoard/Schema/Source/Users.pm @@ -1,8 +1,10 @@ package CharmBoard::Schema::Source::Users; + +use utf8; use strict; use warnings; use experimental qw(try smartmatch); -use utf8; + use base qw(DBIx::Class::Core); __PACKAGE__->table('users'); diff --git a/script/CharmBoard b/script/CharmBoard index 6f7dc61..6e04eca 100755 --- a/script/CharmBoard +++ b/script/CharmBoard @@ -1,8 +1,9 @@ #!/usr/bin/env perl -use experimental qw(try smartmatch); + +use utf8; use strict; use warnings; -use utf8; +use experimental qw(try smartmatch); use Mojo::File qw(curfile); use lib curfile->dirname->sibling('lib')->to_string; diff --git a/templates/index.html.ep b/templates/index.html.ep index bf3acb8..12c6cf2 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -22,6 +22,7 @@ foreach my $category ($categoryTree->getAllChildren) { %> $category->getNodeValue, $self->schema->resultset('Categories')-> title_from_id($category->getNodeValue)) %> + <% say ('$category: ' . $category); %> <% foreach my $subforum ($category->getAllChildren) { %> <%= $subfItem->(