diff --git a/database.sql b/database.sql index bc11a25..6209daa 100644 --- a/database.sql +++ b/database.sql @@ -1,5 +1,5 @@ -- --- File generated with SQLiteStudio v3.4.4 on Fri. May 5 22:21:17 2023 +-- File generated with SQLiteStudio v3.4.4 on Sat. May 6 00:01:26 2023 -- -- Text encoding used: UTF-8 -- @@ -8,12 +8,7 @@ BEGIN TRANSACTION; -- Table: categories DROP TABLE IF EXISTS categories; -CREATE TABLE IF NOT EXISTS "categories" ( - "cat_id" INTEGER NOT NULL UNIQUE, - "cat_name" TEXT, - "cat_desc" TEXT, - PRIMARY KEY("cat_id" AUTOINCREMENT) -); +CREATE TABLE IF NOT EXISTS categories (cat_id INTEGER NOT NULL UNIQUE, cat_name TEXT, PRIMARY KEY (cat_id AUTOINCREMENT)); -- Table: posts DROP TABLE IF EXISTS posts; @@ -36,9 +31,13 @@ CREATE TABLE IF NOT EXISTS "session" ( PRIMARY KEY("user_id") ); +-- Table: subforums +DROP TABLE IF EXISTS subforums; +CREATE TABLE IF NOT EXISTS subforums (subf_id INTEGER PRIMARY KEY UNIQUE NOT NULL, subf_cat INTEGER REFERENCES categories (cat_id) UNIQUE NOT NULL, subf_name TEXT NOT NULL, subf_desc); + -- Table: threads DROP TABLE IF EXISTS threads; -CREATE TABLE IF NOT EXISTS threads (thread_id INTEGER NOT NULL, thread_title TEXT NOT NULL, thread_cat INTEGER REFERENCES categories (cat_id), PRIMARY KEY (thread_id AUTOINCREMENT)); +CREATE TABLE IF NOT EXISTS threads (thread_id INTEGER NOT NULL, thread_title TEXT NOT NULL, thread_subf INTEGER REFERENCES categories (cat_id), PRIMARY KEY (thread_id AUTOINCREMENT)); -- Table: users DROP TABLE IF EXISTS users; diff --git a/lib/CharmBoard/Controller/Auth.pm b/lib/CharmBoard/Controller/Auth.pm index 80473f3..db24b0f 100644 --- a/lib/CharmBoard/Controller/Auth.pm +++ b/lib/CharmBoard/Controller/Auth.pm @@ -32,8 +32,8 @@ sub registration_do ($app) { # check to make sure username and/or email isn't already in use; # if not, continue with registration - my $userCheck = $app->schema->resultset('User')->search({username => $username})->single; - my $emailCheck = $app->schema->resultset('User')->search({email => $email})->single; + my $userCheck = $app->schema->resultset('Users')->search({username => $username})->single; + my $emailCheck = $app->schema->resultset('Users')->search({email => $email})->single; if ( $userCheck || $emailCheck ) { if ( $userCheck && $emailCheck ) { # notify user that username and email are both already being used @@ -51,7 +51,7 @@ sub registration_do ($app) { } else { $password = $app->pepper . ':' . $password; my ($hash, $salt) = pass_gen($password); - $app->schema->resultset('User')->create({ + $app->schema->resultset('Users')->create({ username => $username, email => $email, password => $hash, diff --git a/lib/CharmBoard/Crypt/Password.pm b/lib/CharmBoard/Crypt/Password.pm index 6287a54..5c2934a 100644 --- a/lib/CharmBoard/Crypt/Password.pm +++ b/lib/CharmBoard/Crypt/Password.pm @@ -3,7 +3,7 @@ use Authen::Passphrase::Argon2; use Exporter qw(import); -our @EXPORT = qw/ pass_gen /; +our @EXPORT = qw(pass_gen); sub pass_gen ($) { my $argon2 = Authen::Passphrase::Argon2->new( diff --git a/lib/CharmBoard/Schema/Result/Categories.pm b/lib/CharmBoard/Schema/Result/Categories.pm index d6047fb..894e43f 100644 --- a/lib/CharmBoard/Schema/Result/Categories.pm +++ b/lib/CharmBoard/Schema/Result/Categories.pm @@ -1,20 +1,16 @@ package CharmBoard::Schema::Result::Categories; -use base qw/DBIx::Class::Core/; +use base qw(DBIx::Class::Core); __PACKAGE__->table('categories'); __PACKAGE__->add_columns( cat_id => { data_type => 'integer', is_auto_increment => 1, - is_nullable => 1 + is_nullable => 0, }, cat_name => { data_type => 'text', - is_nullable => 0 - }, - cat_desc => { - data_type => 'text', - is_nullable => 1 + is_nullable => 0, }); __PACKAGE__->set_primary_key('cat_id'); diff --git a/lib/CharmBoard/Schema/Result/Posts.pm b/lib/CharmBoard/Schema/Result/Posts.pm index 76c3120..47a6143 100644 --- a/lib/CharmBoard/Schema/Result/Posts.pm +++ b/lib/CharmBoard/Schema/Result/Posts.pm @@ -1,28 +1,38 @@ package CharmBoard::Schema::Result::Posts; -use base qw/DBIx::Class::Core/; +use base qw(DBIx::Class::Core); __PACKAGE__->table('posts'); __PACKAGE__->add_columns( post_id => { data_type => 'integer', is_auto_increment => 1, - is_nullable => 0 + is_nullable => 0, }, user_id => { data_type => 'integer', is_auto_increment => 1, - is_nullable => 0 + is_nullable => 0, }, thread_id => { data_type => 'integer', is_auto_increment => 1, - is_nullable => 0 + is_nullable => 0, }, post_date => { data_type => 'integer', is_auto_increment => 1, - is_nullable => 0 + is_nullable => 0, }); __PACKAGE__->set_primary_key('post_id'); +__PACKAGE__->belongs_to( + user_id => + 'CharmBoard::Schema::Result::Users', + 'user_id' +); +__PACKAGE__->belongs_to( + thread_id => + 'CharmBoard::Schema::Result::Threads', + 'thread_id' +); 1 \ No newline at end of file diff --git a/lib/CharmBoard/Schema/Result/Session.pm b/lib/CharmBoard/Schema/Result/Session.pm index e3dbe20..77adedb 100644 --- a/lib/CharmBoard/Schema/Result/Session.pm +++ b/lib/CharmBoard/Schema/Result/Session.pm @@ -1,5 +1,5 @@ package CharmBoard::Schema::Result::Session; -use base qw/DBIx::Class::Core/; +use base qw(DBIx::Class::Core); __PACKAGE__->table('session'); __PACKAGE__->add_columns( @@ -9,12 +9,17 @@ __PACKAGE__->add_columns( }, session_id => { data_type => 'text', - is_nullable => 0 + is_nullable => 0, }, session_expiry => { data_type => 'integer', - is_nullable => 0 + is_nullable => 0, }); __PACKAGE__->set_primary_key('user_id'); +__PACKAGE__->belongs_to( + user_id => + 'CharmBoard::Schema::Result::Users', + 'user_id' +); 1 \ No newline at end of file diff --git a/lib/CharmBoard/Schema/Result/Subforums.pm b/lib/CharmBoard/Schema/Result/Subforums.pm new file mode 100644 index 0000000..182f4f1 --- /dev/null +++ b/lib/CharmBoard/Schema/Result/Subforums.pm @@ -0,0 +1,30 @@ +package CharmBoard::Schema::Result::Subforums; +use base qw(DBIx::Class::Core); + +__PACKAGE__->table('subforums'); +__PACKAGE__->add_columns( + subf_id => { + data_type => 'integer', + is_auto_increment => 1, + is_nullable => 0, + }, + subf_cat => { + data_type => 'integer', + is_nullable => 0, + }, + subf_name => { + data_type => 'text', + is_nullable => 0, + }, + subf_desc => { + data_type => 'text', + is_nullable => 1, + }); +__PACKAGE__->set_primary_key('subf_id'); +__PACKAGE__->belongs_to( + subf_cat => + 'CharmBoard::Schema::Result::Categories', + {'foreign.cat_id' => 'self.subf_cat'} +); + +1 \ No newline at end of file diff --git a/lib/CharmBoard/Schema/Result/Threads.pm b/lib/CharmBoard/Schema/Result/Threads.pm index 3e61141..9a577a3 100644 --- a/lib/CharmBoard/Schema/Result/Threads.pm +++ b/lib/CharmBoard/Schema/Result/Threads.pm @@ -1,21 +1,26 @@ package CharmBoard::Schema::Result::Threads; -use base qw/DBIx::Class::Core/; +use base qw(DBIx::Class::Core); __PACKAGE__->table('threads'); __PACKAGE__->add_columns( - thread_id => { + thread_id => { data_type => 'integer', is_auto_increment => 1, - is_nullable => 0 + is_nullable => 0, }, - thread_title => { + thread_title => { data_type => 'text', - is_nullable => 0 + is_nullable => 0, }, - thread_cat => { + thread_subf => { data_type => 'integer', - is_nullable => 1 + is_nullable => 1, }); __PACKAGE__->set_primary_key('thread_id'); +__PACKAGE__->belongs_to( + thread_subf => + 'CharmBoard::Schema::Result::Subforums', + {'foreign.subf_id' => 'self.thread_subf'} +); 1 \ No newline at end of file diff --git a/lib/CharmBoard/Schema/Result/User.pm b/lib/CharmBoard/Schema/Result/Users.pm similarity index 89% rename from lib/CharmBoard/Schema/Result/User.pm rename to lib/CharmBoard/Schema/Result/Users.pm index 69f49eb..35eb272 100644 --- a/lib/CharmBoard/Schema/Result/User.pm +++ b/lib/CharmBoard/Schema/Result/Users.pm @@ -1,5 +1,5 @@ -package CharmBoard::Schema::Result::User; -use base qw/DBIx::Class::Core/; +package CharmBoard::Schema::Result::Users; +use base qw(DBIx::Class::Core); __PACKAGE__->table('users'); __PACKAGE__->add_columns(