3 # Copyright 2015 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 my ($template, $loggedinuser, $cookie) = get_template_and_user({
34 template_name => 'opac-apikeys.tt',
38 flagsrequired => {borrow => 1},
41 my $borrowernumber = $loggedinuser;
42 my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
43 my $op = $cgi->param('op');
46 if ($op eq 'generate') {
47 my $apikey = new Koha::ApiKey;
48 $apikey->borrowernumber($borrowernumber);
49 $apikey->api_key(String::Random->new->randregex('[a-zA-Z0-9]{32}'));
51 print $cgi->redirect('/cgi-bin/koha/opac-apikeys.pl');
55 if ($op eq 'delete') {
56 my $key = $cgi->param('key');
57 my $api_key = Koha::ApiKeys->find({borrowernumber => $borrowernumber, api_key => $key});
61 print $cgi->redirect('/cgi-bin/koha/opac-apikeys.pl');
65 if ($op eq 'revoke') {
66 my $key = $cgi->param('key');
67 my $api_key = Koha::ApiKeys->find({borrowernumber => $borrowernumber, api_key => $key});
72 print $cgi->redirect('/cgi-bin/koha/opac-apikeys.pl');
76 if ($op eq 'activate') {
77 my $key = $cgi->param('key');
78 my $api_key = Koha::ApiKeys->find({borrowernumber => $borrowernumber, api_key => $key});
83 print $cgi->redirect('/cgi-bin/koha/opac-apikeys.pl');
88 my @api_keys = Koha::ApiKeys->search({borrowernumber => $borrowernumber});
92 api_keys => \@api_keys,
93 borrower => $borrower,
94 borrowernumber => $borrowernumber,
97 output_html_with_http_headers $cgi, $cookie, $template->output;