-#!/usr/bin/env perl
+#!/usr/bin/perl
# This file is part of Koha.
#
use Koha::Patrons;
use Koha::Token;
-my $cgi = new CGI;
+my $cgi = CGI->new;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ template_name => 'members/apikeys.tt',
query => $cgi,
type => 'intranet',
- authnotrequired => 0,
- flagsrequired => { borrowers => 1 },
+ flagsrequired => { borrowers => 'edit_borrowers' },
}
);
$patron = Koha::Patrons->find($patron_id) if $patron_id;
-if ( not defined $patron ) {
+if ( not defined $patron or
+ not C4::Context->preference('RESTOAuth2ClientCredentials') ) {
# patron_id invalid -> exit
print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
$op eq 'revoke' or
$op eq 'activate' ) {
- die "Wrong CSRF token"
- unless Koha::Token->new->check_csrf({
- session_id => scalar $cgi->cookie('CGISESSID'),
- token => scalar $cgi->param('csrf_token'),
- });
+ output_and_exit( $cgi, $cookie, $template, 'wrong_csrf_token' )
+ unless Koha::Token->new->check_csrf({
+ session_id => scalar $cgi->cookie('CGISESSID'),
+ token => scalar $cgi->param('csrf_token'),
+ });
}
if ($op) {