diff --git a/lib/PostText/Controller/Moderator.pm b/lib/PostText/Controller/Moderator.pm index 3419529..9016c0f 100644 --- a/lib/PostText/Controller/Moderator.pm +++ b/lib/PostText/Controller/Moderator.pm @@ -8,8 +8,8 @@ sub login($self) { my $v; #Already logged in? - return $self->redirect_to('mod_list') - if $self->session('mod_id') =~ /^\d$/; + return $self->redirect_to('mod_list') + if defined $self->session('mod_id'); $v = $self->validation if $self->req->method eq 'POST'; @@ -36,13 +36,15 @@ sub login($self) { return $self->redirect_to('mod_list'); } else { - $self->stash(status => 403); - $self->flash(error => 'Invalid login! 🧐') + $self->stash( + status => 403, + error => 'Invalid login! 🧐' + ); } } } - $self->render; + return $self->render; } sub logout($self) { diff --git a/t/moderator.t b/t/moderator.t index 3dd6844..c9ddbc3 100644 --- a/t/moderator.t +++ b/t/moderator.t @@ -15,7 +15,13 @@ my %invalid_login = ( ); subtest Login => sub { - $t->post_ok('/login', form => \%invalid_login)->status_is(403); + $t->get_ok('/login') + ->status_is(200) + ->text_like(h2 => qr/Moderator Login/); + + $t->post_ok('/login', form => \%invalid_login) + ->status_is(403) + ->text_like(p => qr/Invalid login/); $t->post_ok('/login', form => \%valid_login) ->status_is(302) diff --git a/templates/layouts/main.html.ep b/templates/layouts/main.html.ep index 0ba3ea7..716f431 100644 --- a/templates/layouts/main.html.ep +++ b/templates/layouts/main.html.ep @@ -14,6 +14,8 @@
<% if (flash 'error') { =%>

<%= flash 'error' %>

+<% } elsif (stash 'error') { =%> +

<%= stash 'error' %>

<% } =%> <% if (flash 'info') { =%>

<%= flash 'info' %>