From f7030968d398855bf308587db8b11a100aae8178 Mon Sep 17 00:00:00 2001 From: swag Date: Sun, 27 Nov 2022 23:56:35 -0500 Subject: [PATCH] Some clean-up --- lib/PostText/Controller/Moderator.pm | 12 +++++++----- t/moderator.t | 8 +++++++- templates/layouts/main.html.ep | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) 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' %>