Fix category and subforum listing on index + misc
This commit is contained in:
parent
e12eeebb6e
commit
45343a87fd
|
@ -3,7 +3,6 @@ package CharmBoard::Controller::Index;
|
||||||
use utf8;
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use feature qw(say unicode_strings);
|
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
|
|
||||||
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||||
|
@ -19,27 +18,28 @@ sub index {
|
||||||
# create a Tree::Simple object that will contain the list
|
# create a Tree::Simple object that will contain the list
|
||||||
# of categories and the subforums that belong to them
|
# of categories and the subforums that belong to them
|
||||||
my $tree =
|
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) {
|
foreach my $iterCat (@allCat) {
|
||||||
# create branch of subfList for the current category
|
# create branch of ROOT for the current category
|
||||||
|
|
||||||
$catBranch =
|
$catBranch =
|
||||||
Tree::Simple->new($iterCat, $tree);
|
Tree::Simple->new($iterCat, $tree);
|
||||||
|
|
||||||
# fetch all subforums that belong to this category
|
# fetch all subforums that belong to this category
|
||||||
$fetchSubf =
|
@fetchSubf =
|
||||||
$self->schema->resultset('Subforums')
|
$self->schema->resultset('Subforums')
|
||||||
->fetch_by_cat($iterCat);
|
->fetch_by_cat($iterCat);
|
||||||
|
|
||||||
# add each fetched subforum as children of the branch
|
# add each fetched subforum as children of the branch
|
||||||
# for the current category
|
# for the current category
|
||||||
foreach my $iterSubf ($fetchSubf) {
|
foreach my $iterSubf (@fetchSubf) {
|
||||||
Tree::Simple->new($iterSubf, $catBranch)}}
|
Tree::Simple->new($iterSubf, $catBranch)}}
|
||||||
|
|
||||||
$self->render(
|
$self->render(
|
||||||
template => 'index',
|
template => 'index',
|
||||||
categoryTree => $tree)}
|
categoryTree => $tree)}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
__END__
|
__END__
|
|
@ -1,15 +1,17 @@
|
||||||
package CharmBoard::Controller::Login;
|
package CharmBoard::Controller::Login;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||||
use CharmBoard::Crypt::Password;
|
use CharmBoard::Crypt::Password;
|
||||||
use CharmBoard::Crypt::Seasoning;
|
use CharmBoard::Crypt::Seasoning;
|
||||||
|
|
||||||
sub login {
|
sub login {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
$self->render(
|
$self->render(
|
||||||
template => 'login',
|
template => 'login',
|
||||||
error => $self->flash('error'),
|
error => $self->flash('error'),
|
||||||
|
@ -56,16 +58,16 @@ sub login_do {
|
||||||
session_expiry => time + 604800,
|
session_expiry => time + 604800,
|
||||||
is_ip_bound => 0,
|
is_ip_bound => 0,
|
||||||
bound_ip => undef }) or die;
|
bound_ip => undef }) or die;
|
||||||
|
|
||||||
# now create session cookie for user
|
# now create session cookie for user
|
||||||
$self->session(is_auth => 1);
|
$self->session(is_auth => 1);
|
||||||
$self->session(user_id => $userID);
|
$self->session(user_id => $userID);
|
||||||
$self->session(session_key => $sessionKey);
|
$self->session(session_key => $sessionKey);
|
||||||
$self->session(expiration => 604800);
|
$self->session(expiration => 604800);
|
||||||
|
|
||||||
# redirect to index upon success
|
# redirect to index upon success
|
||||||
$self->redirect_to('/')}
|
$self->redirect_to('/')}
|
||||||
|
|
||||||
catch ($catchError) { # redirect to login page on fail
|
catch ($catchError) { # redirect to login page on fail
|
||||||
print $catchError;
|
print $catchError;
|
||||||
$self->flash(error => 'Your username and password were correct,
|
$self->flash(error => 'Your username and password were correct,
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package CharmBoard::Controller::Logout;
|
package CharmBoard::Controller::Logout;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||||
|
|
||||||
sub logout_do {
|
sub logout_do {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
# destroy entry for this session in the database
|
# destroy entry for this session in the database
|
||||||
$self->schema->resultset('Session')->search({
|
$self->schema->resultset('Session')->search({
|
||||||
session_key => $self->session('session_key')})->delete;
|
session_key => $self->session('session_key')})->delete;
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package CharmBoard::Controller::Register;
|
package CharmBoard::Controller::Register;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||||
use CharmBoard::Crypt::Password;
|
use CharmBoard::Crypt::Password;
|
||||||
|
|
||||||
# initial registration page
|
# initial registration page
|
||||||
sub register {
|
sub register {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->render(
|
$self->render(
|
||||||
template => 'register',
|
template => 'register',
|
||||||
|
@ -15,9 +17,9 @@ sub register {
|
||||||
message => $self->flash('message'))};
|
message => $self->flash('message'))};
|
||||||
|
|
||||||
# process submitted registration form
|
# process submitted registration form
|
||||||
sub register_do {
|
sub register_do {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
my $username = $self->param('username');
|
my $username = $self->param('username');
|
||||||
my $email = $self->param('email');
|
my $email = $self->param('email');
|
||||||
my $password = $self->param('password');
|
my $password = $self->param('password');
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Crypt::Password;
|
package CharmBoard::Crypt::Password;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use Authen::Passphrase::Argon2;
|
use Authen::Passphrase::Argon2;
|
||||||
use CharmBoard::Crypt::Seasoning;
|
use CharmBoard::Crypt::Seasoning;
|
||||||
|
|
||||||
|
@ -16,7 +18,7 @@ sub passgen {
|
||||||
cost => 17,
|
cost => 17,
|
||||||
factor => '32M',
|
factor => '32M',
|
||||||
parallelism => 1,
|
parallelism => 1,
|
||||||
size => 32 );
|
size => 32 );
|
||||||
|
|
||||||
return ($argon2->salt_hex, $argon2->hash_hex)};
|
return ($argon2->salt_hex, $argon2->hash_hex)};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Crypt::Seasoning;
|
package CharmBoard::Crypt::Seasoning;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use Math::Random::Secure qw(irand);
|
use Math::Random::Secure qw(irand);
|
||||||
|
|
||||||
use Exporter qw(import);
|
use Exporter qw(import);
|
||||||
|
@ -18,7 +20,7 @@ sub seasoning {
|
||||||
while (length($blend) < $_[0]) {
|
while (length($blend) < $_[0]) {
|
||||||
# gen num to choose char for $blend
|
# gen num to choose char for $blend
|
||||||
$blend = $blend . $spices[irand(@spices)]};
|
$blend = $blend . $spices[irand(@spices)]};
|
||||||
|
|
||||||
return ($blend); }
|
return ($blend); }
|
||||||
|
|
||||||
1;
|
1;
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Schema;
|
package CharmBoard::Schema;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use base qw(DBIx::Class::Schema);
|
use base qw(DBIx::Class::Schema);
|
||||||
|
|
||||||
__PACKAGE__->load_namespaces(
|
__PACKAGE__->load_namespaces(
|
||||||
|
|
|
@ -3,7 +3,6 @@ package CharmBoard::Schema::Set::Categories;
|
||||||
use utf8;
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use feature qw(say unicode_strings);
|
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
|
|
||||||
use base 'DBIx::Class::ResultSet';
|
use base 'DBIx::Class::ResultSet';
|
||||||
|
|
|
@ -3,7 +3,6 @@ package CharmBoard::Schema::Set::Subforums;
|
||||||
use utf8;
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use feature qw(say unicode_strings);
|
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
|
|
||||||
use base 'DBIx::Class::ResultSet';
|
use base 'DBIx::Class::ResultSet';
|
||||||
|
@ -14,8 +13,7 @@ sub fetch_by_cat {
|
||||||
my $fetch =
|
my $fetch =
|
||||||
$set->search(
|
$set->search(
|
||||||
{'subf_cat' => $_[0] },
|
{'subf_cat' => $_[0] },
|
||||||
{order_by => 'subf_rank',
|
{order_by => 'subf_rank'});
|
||||||
group_by => undef});
|
|
||||||
|
|
||||||
return($fetch->get_column('subf_id')->all)}
|
return($fetch->get_column('subf_id')->all)}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Schema::Source::Categories;
|
package CharmBoard::Schema::Source::Categories;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use base qw(DBIx::Class::Core);
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('categories');
|
__PACKAGE__->table('categories');
|
||||||
|
@ -17,7 +19,7 @@ __PACKAGE__->add_columns(
|
||||||
cat_name => {
|
cat_name => {
|
||||||
data_type => 'text',
|
data_type => 'text',
|
||||||
is_nullable => 0, });
|
is_nullable => 0, });
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key('cat_id');
|
__PACKAGE__->set_primary_key('cat_id');
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Schema::Source::Posts;
|
package CharmBoard::Schema::Source::Posts;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use base qw(DBIx::Class::Core);
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('posts');
|
__PACKAGE__->table('posts');
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Schema::Source::Session;
|
package CharmBoard::Schema::Source::Session;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use base qw(DBIx::Class::Core);
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('sessions');
|
__PACKAGE__->table('sessions');
|
||||||
|
@ -22,7 +24,7 @@ __PACKAGE__->add_columns(
|
||||||
bound_ip => {
|
bound_ip => {
|
||||||
data_type => 'text',
|
data_type => 'text',
|
||||||
is_nullable => 1, });
|
is_nullable => 1, });
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key('session_key');
|
__PACKAGE__->set_primary_key('session_key');
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Schema::Source::Subforums;
|
package CharmBoard::Schema::Source::Subforums;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use base qw(DBIx::Class::Core);
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('subforums');
|
__PACKAGE__->table('subforums');
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Schema::Source::Threads;
|
package CharmBoard::Schema::Source::Threads;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use base qw(DBIx::Class::Core);
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('threads');
|
__PACKAGE__->table('threads');
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package CharmBoard::Schema::Source::Users;
|
package CharmBoard::Schema::Source::Users;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use experimental qw(try smartmatch);
|
use experimental qw(try smartmatch);
|
||||||
use utf8;
|
|
||||||
use base qw(DBIx::Class::Core);
|
use base qw(DBIx::Class::Core);
|
||||||
|
|
||||||
__PACKAGE__->table('users');
|
__PACKAGE__->table('users');
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
use experimental qw(try smartmatch);
|
|
||||||
|
use utf8;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use experimental qw(try smartmatch);
|
||||||
|
|
||||||
use Mojo::File qw(curfile);
|
use Mojo::File qw(curfile);
|
||||||
use lib curfile->dirname->sibling('lib')->to_string;
|
use lib curfile->dirname->sibling('lib')->to_string;
|
||||||
|
|
|
@ -22,6 +22,7 @@ foreach my $category ($categoryTree->getAllChildren) { %>
|
||||||
$category->getNodeValue,
|
$category->getNodeValue,
|
||||||
$self->schema->resultset('Categories')->
|
$self->schema->resultset('Categories')->
|
||||||
title_from_id($category->getNodeValue)) %>
|
title_from_id($category->getNodeValue)) %>
|
||||||
|
<% say ('$category: ' . $category); %>
|
||||||
<%
|
<%
|
||||||
foreach my $subforum ($category->getAllChildren) { %>
|
foreach my $subforum ($category->getAllChildren) { %>
|
||||||
<%= $subfItem->(
|
<%= $subfItem->(
|
||||||
|
|
Loading…
Reference in New Issue