diff --git a/lib/CharmBoard.pm b/lib/CharmBoard.pm index 7c500c7..a42d581 100644 --- a/lib/CharmBoard.pm +++ b/lib/CharmBoard.pm @@ -67,17 +67,26 @@ sub startup { # router my $r = $self->routes; + # controller routes + ## index page + $r->get('/')->to( + controller => 'Controller::Index', + action => 'index' + ); # view subforum $r->get('/subforum/:id')->to( controller => 'Controller::ViewSubf', action => 'subf_view' ); - # controller routes - ## index page - $r->get('/')->to( - controller => 'Controller::Index', - action => 'index' + # create thread + $r->get('/thread/new/:id')->to( + controller => 'Controller::NewThread', + action => 'thread_compose' + ); + $r->post('/thread/new/:id')->to( + controller => 'Controller::NewThread', + action => 'thread_submit' ); ## registration page diff --git a/lib/CharmBoard/Controller/NewThread.pm b/lib/CharmBoard/Controller/NewThread.pm new file mode 100644 index 0000000..f4aa097 --- /dev/null +++ b/lib/CharmBoard/Controller/NewThread.pm @@ -0,0 +1,51 @@ +package CharmBoard::Controller::NewThread; + +use utf8; +use strict; +use warnings; +use experimental qw(try smartmatch); + +use Mojo::Base 'Mojolicious::Controller', -signatures; + +sub thread_compose { + my $self = shift; + + my $subf_id = $self->param('id'); + my $subf_cat = + $self->schema->resultset('Subforums')->cat_from_id($subf_id); + my $cat_title = + $self->schema->resultset('Categories') + ->title_from_id($subf_cat); + + $self->render( + template => 'thread_compose', + subf_id => $subf_id, + cat_title => $cat_title, + subf_title => $self->schema->resultset('Subforums') + ->title_from_id($subf_id), + error => $self->flash('error'), + message => $self->flash('message') + ) +} + +sub thread_submit { + my $self = shift; + + my $thread_title = $self->param('thread-title'); + my $post_content = $self->param('post-content'); + my $post_time = time; + + my $catch_error; + + # make sure post data is valid + try { + ($thread_title, $post_content) + or die "Please fill both the title and post content fields" + } catch ($catch_error) { + $self->flash(error => $catch_error); + $self->redirect_to('/thread/new/:id') + } +} + +1; +__END__ diff --git a/lib/CharmBoard/Controller/ViewSubf.pm b/lib/CharmBoard/Controller/ViewSubf.pm index 1273c8e..e65aed5 100644 --- a/lib/CharmBoard/Controller/ViewSubf.pm +++ b/lib/CharmBoard/Controller/ViewSubf.pm @@ -31,4 +31,4 @@ sub subf_view { } 1; -__END__ +__END__ \ No newline at end of file diff --git a/lib/CharmBoard/Schema/Source/Users.pm b/lib/CharmBoard/Schema/Source/Users.pm index a4cf990..c24a862 100644 --- a/lib/CharmBoard/Schema/Source/Users.pm +++ b/lib/CharmBoard/Schema/Source/Users.pm @@ -9,25 +9,25 @@ use base qw(DBIx::Class::Core); __PACKAGE__->table('users'); __PACKAGE__->add_columns( - user_id => + user_id => { data_type => 'integer', is_numeric => 1, is_nullable => 0, is_auto_increment => 1, }, - username => + username => { data_type => 'text', is_nullable => 0, }, - email => + email => { data_type => 'text', is_nullable => 0, }, - password => + password => { data_type => 'text', is_nullable => 0, }, - salt => + salt => { data_type => 'text', is_nullable => 0, }, diff --git a/templates/index.html.ep b/templates/index.html.ep index 3af54c9..21b338a 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -1,4 +1,5 @@ -% layout 'default', title => $self->board_name; +% layout 'default', +% title => $self->board_name; <% my $cat_header = begin %> % my $_cat_id = shift; my $_name = shift; diff --git a/templates/layouts/default/_header.html.ep b/templates/layouts/default/_header.html.ep index 570a847..a9d37de 100644 --- a/templates/layouts/default/_header.html.ep +++ b/templates/layouts/default/_header.html.ep @@ -3,12 +3,12 @@ my $userControls; # TODO: once implemented, put username + profile link first if ($self->session('is_auth') == 1) { - my $username = + my $username = $userControls = "logout"} else { $userControls = - "login | - register"}; + "login | + register"}; %>

<%== $self->board_name %>

<%== $userControls %>

\ No newline at end of file diff --git a/templates/login.html.ep b/templates/login.html.ep index 2d2b495..ffa4c1c 100644 --- a/templates/login.html.ep +++ b/templates/login.html.ep @@ -1,4 +1,5 @@ -% layout 'default', title => $self->board_name . ' - Login'; +% layout 'default', +% title => $self->board_name . ' - Login'; % if ($error) {

<%= $error %>

%}; diff --git a/templates/register.html.ep b/templates/register.html.ep index 4694940..710b299 100644 --- a/templates/register.html.ep +++ b/templates/register.html.ep @@ -1,4 +1,5 @@ -% layout 'default', title => $self->board_name . ' - Registration'; +% layout 'default', +% title => $self->board_name . ' - Registration'; % if ($error) {

<%= $error %>

%}; @@ -8,23 +9,23 @@

fields marked with * are required

username: *
email: *
password: *
confirm password: *
\ No newline at end of file diff --git a/templates/subf.html.ep b/templates/subf.html.ep index ca2ebf3..841023d 100644 --- a/templates/subf.html.ep +++ b/templates/subf.html.ep @@ -1,14 +1,16 @@ -% layout 'default', title => $subf_title . ' - ' . $self->board_name; +% layout 'default', +% title => $subf_title . ' - ' . $self->board_name; % my @thread_list = @{stash('thread_list')}; <% my $thread_item = begin %> % my $_thread_id = shift; my $_thread_title = shift;
- +
<% end %> -<%= $self->board_name %> » <%= $cat_title %> » <%= $subf_title %> +<%= $self->board_name %> » <%= $cat_title %> » + <%= $subf_title %>

<% if (! @thread_list) { %> @@ -17,7 +19,7 @@ like to make one? <% } else { foreach my $thread_id (@thread_list) { %> <%= $thread_item->( - $thread_id, - $self->schema->resultset('Threads')-> - title_from_id($thread_id)) %> + $thread_id, + $self->schema->resultset('Threads')-> + title_from_id($thread_id)) %> <% }} %> \ No newline at end of file diff --git a/templates/thread_compose.html.ep b/templates/thread_compose.html.ep new file mode 100644 index 0000000..28c2189 --- /dev/null +++ b/templates/thread_compose.html.ep @@ -0,0 +1,20 @@ +% layout 'default', +% title => 'New thread - ' . $self->board_name; +<%= $self->board_name %> » <%= $cat_title %> » + <%= $subf_title %> » new thread +

+
+
+

+ +
\ No newline at end of file