Bug 13799: Reword 'borrower' to 'patron'
[koha.git] / opac / svc / login
blobe871f7418d916d3ebde9783da7508ec477606276
1 #!/usr/bin/perl
3 # Copyright chris@bigballofwax.co.nz 2013
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 3 of the License, or (at your option) any later
10 # version.
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.
20 use CGI qw ( -utf8 );
21 use strict;
22 use warnings;
23 use C4::Auth;
24 use C4::Context;
26 use LWP::UserAgent;
27 use HTTP::Request::Common qw{ POST };
28 use JSON qw( decode_json );
30 my $url = 'https://verifier.login.persona.org/verify';
32 my $query = CGI->new();
34 my $host = C4::Context->preference('OPACBaseURL');
36 my $assertion = $query->param('assertion');
38 my $ua = LWP::UserAgent->new();
39 my $response =
40 $ua->post( $url, [ 'assertion' => $assertion, 'audience' => $host ] );
42 if ( $response->is_success ) {
43 my $content = $response->decoded_content();
44 my $decoded_json = decode_json($content);
45 my ( $userid, $cookie, $sessionID ) =
46 checkauth( $query, 1, { borrow => 1 }, 'opac', $decoded_json->{'email'} );
47 if ($userid) { # a valid user has logged in
48 print $query->header( -cookie => $cookie );
49 print $decoded_json;
51 else {
52 # logged in with an email that isn't associated with a borrower
53 die "Email not associated with a borrower";
56 else {
57 warn $response->status_line, "\n";