add api user role and fix api auth failure response

This commit is contained in:
Oliver Gorwits
2018-12-31 19:30:41 +00:00
parent 1a038079bf
commit 4691808fa6
2 changed files with 13 additions and 1 deletions

View File

@@ -19,6 +19,9 @@ __PACKAGE__->result_source_instance->view_definition(<<ENDSQL
UNION
SELECT username, 'ldap' AS role FROM users
WHERE ldap
UNION
SELECT username, 'api', AS role FROM users
WHERE token AND token_from
ENDSQL
);

View File

@@ -59,7 +59,16 @@ hook 'before' => sub {
};
get qr{^/(?:login(?:/denied)?)?} => sub {
if (param('return_url') and param('return_url') =~ m{^/api/}) {
status 403;
return to_json {
error => 'not authorized',
return_url => param('return_url'),
};
}
else {
template 'index', { return_url => param('return_url') };
}
};
# override default login_handler so we can log access in the database