broken refactor but need to leave now...
This commit is contained in:
@@ -5,7 +5,6 @@ use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
use Dancer::Plugin::Swagger;
|
||||
|
||||
use App::Netdisco::Util::Web 'request_is_api';
|
||||
use MIME::Base64;
|
||||
|
||||
hook 'before' => sub {
|
||||
@@ -49,7 +48,7 @@ hook 'before' => sub {
|
||||
session(logged_in_user => 'guest');
|
||||
session(logged_in_user_realm => 'users');
|
||||
}
|
||||
elsif (request_is_api()
|
||||
elsif (request->is_api
|
||||
and request->header('Authorization')) {
|
||||
|
||||
my $token = request->header('Authorization');
|
||||
@@ -68,7 +67,7 @@ hook 'before' => sub {
|
||||
|
||||
# user redirected here (POST -> GET) when login fails
|
||||
get qr{^/(?:login(?:/denied)?)?} => sub {
|
||||
if (request_is_api()) {
|
||||
if (request->is_api) {
|
||||
status('unauthorized');
|
||||
return to_json {
|
||||
error => 'not authorized',
|
||||
@@ -96,7 +95,7 @@ swagger_path {
|
||||
},
|
||||
},
|
||||
post qr{^/(?:api/)?login$} => sub {
|
||||
my $mode = (request_is_api() ? 'API' : 'WebUI');
|
||||
my $mode = (request->is_api ? 'API' : 'WebUI');
|
||||
|
||||
my $x = params; use DDP; p $x;
|
||||
|
||||
@@ -173,7 +172,7 @@ swagger_path {
|
||||
responses => { default => { examples => { 'application/json' => {} } } },
|
||||
},
|
||||
get qr{^/(?:api/)?logout$} => sub {
|
||||
my $mode = (request_is_api() ? 'API' : 'WebUI');
|
||||
my $mode = (request->is_api ? 'API' : 'WebUI');
|
||||
|
||||
# clear out API token
|
||||
my $user = schema('netdisco')->resultset('User')
|
||||
|
||||
@@ -5,9 +5,6 @@ use Dancer::Plugin::Ajax;
|
||||
|
||||
use Dancer::Plugin::Swagger;
|
||||
|
||||
use App::Netdisco::Util::Web
|
||||
qw/request_is_api interval_to_daterange/;
|
||||
|
||||
# setup for swagger API
|
||||
my $swagger = Dancer::Plugin::Swagger->instance->doc;
|
||||
$swagger->{schemes} = ['http','https'];
|
||||
@@ -30,11 +27,6 @@ $swagger->{securityDefinitions} = {
|
||||
};
|
||||
$swagger->{security} = [ { APIKeyHeader => [] } ];
|
||||
|
||||
# support for checking if this is an api request even after forward
|
||||
hook 'before' => sub {
|
||||
vars->{'orig_path'} = request->path unless request->is_forward;
|
||||
};
|
||||
|
||||
# workaround for Swagger plugin weird response body
|
||||
hook 'after' => sub {
|
||||
my $r = shift; # a Dancer::Response
|
||||
@@ -50,7 +42,6 @@ any '/api/:type/:identifier/:method' => require_login sub {
|
||||
pass unless setting('api_enabled')
|
||||
->{ params->{'type'} }->{ params->{'method'} };
|
||||
|
||||
vars->{'is_api'} = 1;
|
||||
my $target =
|
||||
sprintf '/ajax/content/%s/%s', params->{'type'}, params->{'method'};
|
||||
forward $target, { tab => params->{'method'}, q => params->{'identifier'} };
|
||||
|
||||
@@ -3,7 +3,6 @@ package App::Netdisco::Web::Plugin;
|
||||
use Dancer ':syntax';
|
||||
use Dancer::Plugin;
|
||||
|
||||
use App::Netdisco::Util::Web 'request_is_api';
|
||||
use Path::Class 'dir';
|
||||
|
||||
set(
|
||||
@@ -25,7 +24,7 @@ set(
|
||||
config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} ||= [ setting('views') ];
|
||||
|
||||
register 'bang' => sub {
|
||||
if (request_is_api()) {
|
||||
if (request->is_api) {
|
||||
content_type('application/json');
|
||||
set serializer => 'JSON';
|
||||
status $_[1];
|
||||
|
||||
@@ -22,7 +22,6 @@ swagger_path {
|
||||
} } },
|
||||
},
|
||||
get '/api/device/:identifier' => require_login sub {
|
||||
vars->{'is_api'} = 1;
|
||||
forward '/ajax/content/device/details',
|
||||
{ tab => 'details', q => params->{'identifier'} };
|
||||
};
|
||||
@@ -45,7 +44,7 @@ get '/ajax/content/device/details' => require_login sub {
|
||||
delete $results[0]->{'snmp_comm'};
|
||||
$results[0]->{'power'} = \@power;
|
||||
|
||||
if (vars->{'is_api'}) {
|
||||
if (request->is_api) {
|
||||
content_type('application/json');
|
||||
to_json { device => $results[0] };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user