redirect users after login to protected page

This commit is contained in:
Daniel Friesel 2019-03-10 19:32:45 +01:00
parent c27c108f48
commit 5970a5a350
2 changed files with 5 additions and 2 deletions

View file

@ -920,7 +920,7 @@ post '/login' => sub {
} }
else { else {
if ( $self->authenticate( $user, $password ) ) { if ( $self->authenticate( $user, $password ) ) {
$self->redirect_to('/'); $self->redirect_to( $self->req->param('redirect_to') // '/' );
} }
else { else {
my $data = $self->get_user_password($user); my $data = $self->get_user_password($user);
@ -1173,7 +1173,7 @@ under sub {
if ( $self->is_user_authenticated ) { if ( $self->is_user_authenticated ) {
return 1; return 1;
} }
$self->render('login'); $self->render( 'login', redirect_to => $self->req->url );
return undef; return undef;
}; };

View file

@ -76,6 +76,9 @@
<div class="row"> <div class="row">
%= form_for '/login' => (class => 'col s12', method => 'POST') => begin %= form_for '/login' => (class => 'col s12', method => 'POST') => begin
%= csrf_field %= csrf_field
% if (stash('redirect_to')) {
%= hidden_field 'redirect_to' => $redirect_to
% }
<div class="row"> <div class="row">
<div class="input-field col s12"> <div class="input-field col s12">
<i class="material-icons prefix">account_circle</i> <i class="material-icons prefix">account_circle</i>