From c3584056b407d8a19e35cd405ce84776c3c6433e Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Sun, 6 Jun 2021 00:41:27 +0200 Subject: [PATCH] Supporting error printing on Index --- Makefile.PL | 2 +- lib/BeastBB/Controller/Login.pm | 4 +++- lib/BeastBB/Controller/Main.pm | 3 ++- templates/main/Index.html.ep | 3 +++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 648f092..191a6ed 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -15,7 +15,7 @@ package MY { my $return = $self->SUPER::install(@_); $return = [ split /\n/, $return ]; for my $i ( keys @$return ) { - $return->[$i] .= ' install_frontend_and_migrations' + $return->[$i] =~ s/::/:: install_frontend_and_migrations/ if $return->[$i] =~ /^install :/; } return join "\n", @$return; diff --git a/lib/BeastBB/Controller/Login.pm b/lib/BeastBB/Controller/Login.pm index 95bb8f1..f44d5c0 100644 --- a/lib/BeastBB/Controller/Login.pm +++ b/lib/BeastBB/Controller/Login.pm @@ -14,6 +14,8 @@ sub GetLogin { sub Login { my $self = shift; + my $error_url = Mojo::URL->new('/')->query( error => 'You are already logged in.'); + return $self->redirect_to($error_url) if !$self->LoggedUser->IsError; my $user_manager = BeastBB::DAO::UserManager->new( app => $self ); my $username = $self->param('username'); my $password = $self->param('password'); @@ -21,7 +23,7 @@ sub Login { return $self->reply->exception('Request not understood.')->rendered(400) if !defined $username || !defined $password; my $maybe_user = $user_manager->Get( username => $username ); - my $error_url = Mojo::URL->new('/')->query( error => $wrong_auth_error ); + $error_url = Mojo::URL->new('/')->query( error => $wrong_auth_error ); return $self->redirect_to($error_url) if $maybe_user->IsError || !$maybe_user->Content->CheckPasswordLogin( password => $password ); diff --git a/lib/BeastBB/Controller/Main.pm b/lib/BeastBB/Controller/Main.pm index 75d6569..00983bf 100644 --- a/lib/BeastBB/Controller/Main.pm +++ b/lib/BeastBB/Controller/Main.pm @@ -9,12 +9,13 @@ use Mojo::Base 'BeastBB::Controller'; sub Index { my $self = shift; + my $error = $self->param('error'); my $maybe_logged_in_user = $self->LoggedUser; - print Data::Dumper::Dumper $maybe_logged_in_user; if ( $maybe_logged_in_user->IsError ) { delete $self->session->{username} if $maybe_logged_in_user =~ qr/No such user found\./; } + $self->stash( error => $error ); $self->stash( user => !$maybe_logged_in_user->IsError ? $maybe_logged_in_user->Content diff --git a/templates/main/Index.html.ep b/templates/main/Index.html.ep index c0448ab..241a920 100644 --- a/templates/main/Index.html.ep +++ b/templates/main/Index.html.ep @@ -2,3 +2,6 @@ % if (!defined $user) {

Login Signup % } +% if (defined $error) { +

<%= $error %>

+% }