Hydra/33: 'Sign in' should return to the referring page

This commit is contained in:
Rob Vermaas 2010-07-06 07:27:55 +00:00
parent b8b976fb9f
commit 33ef55815e

View file

@ -37,12 +37,19 @@ sub login :Local {
my $username = $c->request->params->{username} || ""; my $username = $c->request->params->{username} || "";
my $password = $c->request->params->{password} || ""; my $password = $c->request->params->{password} || "";
if(! $username && ! defined $c->flash->{afterLogin}) {
my $baseurl = $c->uri_for('/');
my $refurl = $c->request->referer;
$c->flash->{afterLogin} = $refurl if $refurl =~ m/^($baseurl)/ ;
}
if ($username && $password) { if ($username && $password) {
if ($c->authenticate({username => $username, password => $password})) { if ($c->authenticate({username => $username, password => $password})) {
$c->response->redirect( $c->response->redirect(
defined $c->flash->{afterLogin} defined $c->flash->{afterLogin}
? $c->flash->{afterLogin} ? $c->flash->{afterLogin}
: $c->uri_for('/')); : $c->uri_for('/'));
$c->flash->{afterLogin} = undef;
return; return;
} }
$c->stash->{errorMsg} = "Bad username or password."; $c->stash->{errorMsg} = "Bad username or password.";