From 5970a5a350890340821a5418f3aa4607e05f49cb Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 10 Mar 2019 19:32:45 +0100 Subject: [PATCH] redirect users after login to protected page --- index.pl | 4 ++-- templates/login.html.ep | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.pl b/index.pl index b442126..52ec80f 100755 --- a/index.pl +++ b/index.pl @@ -920,7 +920,7 @@ post '/login' => sub { } else { if ( $self->authenticate( $user, $password ) ) { - $self->redirect_to('/'); + $self->redirect_to( $self->req->param('redirect_to') // '/' ); } else { my $data = $self->get_user_password($user); @@ -1173,7 +1173,7 @@ under sub { if ( $self->is_user_authenticated ) { return 1; } - $self->render('login'); + $self->render( 'login', redirect_to => $self->req->url ); return undef; }; diff --git a/templates/login.html.ep b/templates/login.html.ep index fc8bbb8..4c5696d 100644 --- a/templates/login.html.ep +++ b/templates/login.html.ep @@ -76,6 +76,9 @@
%= form_for '/login' => (class => 'col s12', method => 'POST') => begin %= csrf_field + % if (stash('redirect_to')) { + %= hidden_field 'redirect_to' => $redirect_to + % }
account_circle