diff --git a/README.md b/README.md index 6283a75..3a0426f 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ Run the tests locally (against development environment): ## TODOs -1. Actions for creating moderators and resetting passwords +1. Action for resetting passwords +1. Action for locking/unlocking accounts 1. CSS 1. "All new posts flagged" mode (require approval for new posts) diff --git a/lib/PostText.pm b/lib/PostText.pm index fef8b25..610071a 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -58,10 +58,6 @@ sub startup($self) { return undef; }); - $self->helper(is_admin => sub ($c) { - $self->session->{'is_admin'} || undef - }); - # Finish configuring some things $self->secrets($self->config->{'secrets'}) || die $@; @@ -160,6 +156,10 @@ sub startup($self) { ->to('moderator#hidden') ->name('hidden_list'); + $moderator->any([qw{GET POST}], '/create') + ->to('moderator#create') + ->name('create_mod'); + my $mod_thread = $moderator->under('/thread'); $mod_thread->get('/unflag/:thread_id', [thread_id => qr/\d+/]) @@ -188,9 +188,6 @@ sub startup($self) { ->to('moderator#unhide_remark') ->name('unhide_remark'); - # under() for admins - - # Actions to create mods... } 1; diff --git a/lib/PostText/Controller/Moderator.pm b/lib/PostText/Controller/Moderator.pm index 8c839e8..bab59e2 100644 --- a/lib/PostText/Controller/Moderator.pm +++ b/lib/PostText/Controller/Moderator.pm @@ -91,7 +91,7 @@ sub unflag_thread($self) { my $redirect_url = $self->url_for('threads_list')->fragment('info')->to_abs; $self->moderator->unflag_thread($thread_id); - $self->flash(info => "Thread #$thread_id has been unflagged. ◀️"); + $self->flash(info => "Thread #$thread_id has been unflagged. ◀"); $self->redirect_to($redirect_url); } @@ -124,7 +124,7 @@ sub unflag_remark($self) { ->fragment('info')->to_abs; $self->moderator->unflag_remark($remark_id); - $self->flash(info => "Remark #$remark_id has been unflagged. ◀️"); + $self->flash(info => "Remark #$remark_id has been unflagged. ◀"); $self->redirect_to($redirect_url); } @@ -152,4 +152,32 @@ sub unhide_remark($self) { $self->redirect_to($redirect_url); } +sub create($self) { + my $v; + + $v = $self->validation if $self->req->method eq 'POST'; + + if ($v && $v->has_data) { + $v->required('name' ); + $v->required('email' ); + $v->required('password'); + + if ($v->has_error) { + $self->stash(status => 400) + } + else { + my ($name, $email, $password); + + $name = $self->param('name'); + $email = $self->param('email'); + $password = $self->param('password'); + + $self->moderator->create($name, $email, $password); + $self->stash(info => "Created moderator account for $name 🧑‍🏭"); + } + } + + return $self->render; +} + 1; diff --git a/t/moderator.t b/t/moderator.t index 910aefa..af11fa2 100644 --- a/t/moderator.t +++ b/t/moderator.t @@ -83,6 +83,7 @@ subtest Login => sub { ->element_exists('a[href*="/moderator/flagged"]') ->element_exists('a[href*="/moderator/hidden"]' ) ->element_exists('a[href*="/logout"]' ) + ->element_exists('a[href*="/moderator/create"]' ) }; subtest Hidden => sub { @@ -92,6 +93,17 @@ subtest Login => sub { ->element_exists('a[href*="/moderator/flagged"]') ->element_exists('a[href*="/moderator/hidden"]' ) ->element_exists('a[href*="/logout"]' ) + ->element_exists('a[href*="/moderator/create"]' ) + }; + + subtest Create => sub { + $t->get_ok('/moderator/create') + ->status_is(200) + ->text_like(h2 => qr/Create Moderator/) + ->element_exists('a[href*="/moderator/flagged"]') + ->element_exists('a[href*="/moderator/hidden"]' ) + ->element_exists('a[href*="/logout"]' ) + ->element_exists('a[href*="/moderator/create"]' ) }; # Mod session ends @@ -125,6 +137,10 @@ subtest Login => sub { $t->get_ok('/moderator/hidden') ->status_is(302) ->header_like(Location => qr/login/); + + $t->get_ok('/moderator/create') + ->status_is(302) + ->header_like(Location => qr/login/); }; }; diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index de3885a..c708e93 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -7,16 +7,28 @@

Post::Text


<% if (flash 'error') { =%> @@ -27,6 +39,9 @@ <% if (flash 'info') { =%>

<%= flash 'info' %>

<% } =%> +<% if (stash 'info') { =%> +

<%= stash 'info' %>

+<% } =%> <%= content =%>