Fix redirect when accessing a deep link when unauthenticated

This commit is contained in:
Oliver Gorwits
2014-02-08 21:15:50 +00:00
parent 44e35fd316
commit 4c39387477
3 changed files with 10 additions and 6 deletions

View File

@@ -19,6 +19,7 @@
* [#84] No longer use dns as a key into devices; cope with dupe dns (LT)
* Correct date formatting and logic in IP Inventory report
* Fix redirect when accessing a deep link when unauthenticated
2.022000 - 2014-01-26

View File

@@ -5,7 +5,8 @@ use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
hook 'before' => sub {
params->{return_url} ||= uri_for('/inventory');
params->{return_url} ||= ((request->path ne uri_for('/')->path)
? request->path : uri_for('/inventory'));
if (! session('logged_in_user') && request->path ne uri_for('/login')->path) {
if (setting('trust_x_remote_user') and scalar request->header('X-REMOTE_USER')) {
@@ -28,7 +29,7 @@ hook 'before' => sub {
};
get qr{^/(?:login(?:/denied)?)?} => sub {
template 'index';
template 'index', { return_url => params->{return_url} };
};
# override default login_handler so we can log access in the database
@@ -50,7 +51,7 @@ post '/login' => sub {
});
return if request->is_ajax;
redirect params->{return_url} || uri_for('/');
redirect params->{return_url};
}
else {
session->destroy;
@@ -67,7 +68,9 @@ post '/login' => sub {
}
else {
vars->{login_failed}++;
forward uri_for('/login'), { login_failed => 1 }, { method => 'GET' };
forward uri_for('/login'),
{ login_failed => 1, return_url => params->{return_url} },
{ method => 'GET' };
}
}
};

View File

@@ -42,8 +42,8 @@
<input placeholder="Password" class="span2" name="password" type="password"/>
<button type="submit" class="btn btn-info">Log In</button>
</div>
[% IF vars.return_url %]
<input type="hidden" name="path" value="[% vars.return_url | html_entity %]"/>
[% IF params.return_url %]
<input type="hidden" name="return_url" value="[% params.return_url | html_entity %]"/>
[% END %]
</form>
[% ELSE %]