View | Details | Raw Unified | Return to bug 21082
Collapse All | Expand All

(-)a/Koha/ExternalContent/OverDrive.pm (-2 / +26 lines)
Lines 121-127 sub auth_url { Link Here
121
121
122
=head2 auth_by_code($code, $base_url)
122
=head2 auth_by_code($code, $base_url)
123
123
124
  To be called in external/overdrive/auth.pl upon return from OverDrive auth
124
  To be called in external/overdrive/auth.pl upon return from OverDrive Granted auth
125
125
126
=cut
126
=cut
127
127
Lines 139-144 sub auth_by_code { Link Here
139
    return $self->get_return_page_from_koha_session;
139
    return $self->get_return_page_from_koha_session;
140
}
140
}
141
141
142
=head2 auth_by_userid($userid, $password, $website_id, $authorization_name)
143
144
  To be called to check auth of patron using OverDrive Patron Authentication method
145
  This requires a SIP connection configured with OverDrive
146
147
=cut
148
149
sub auth_by_userid {
150
    my $self = shift;
151
    my $userid = shift or croak "No user provided";
152
    my $password = shift;
153
    croak "No password provided" unless ($password || !C4::Context->preference("OverDrivePasswordRequired"));
154
    my $website_id = shift or croak "OverDrive Library ID not provided";
155
    my $authorization_name = shift or croak "OverDrive Authname not provided";
156
157
    my ($access_token, $access_token_type, $auth_token)
158
      = $self->client->auth_by_user_id($userid, $password, $website_id, $authorization_name);
159
    $access_token or die "Invalid OverDrive code returned";
160
    $self->set_token_in_koha_session($access_token, $access_token_type);
161
162
    $self->koha_patron->set({overdrive_auth_token => $auth_token})->store;
163
    return $self->get_return_page_from_koha_session;
164
}
165
142
use constant AUTH_RETURN_HANDLER => "/cgi-bin/koha/external/overdrive/auth.pl";
166
use constant AUTH_RETURN_HANDLER => "/cgi-bin/koha/external/overdrive/auth.pl";
143
sub _return_url {
167
sub _return_url {
144
    my $self = shift;
168
    my $self = shift;
Lines 205-211 sub auth_by_saved_token { Link Here
205
    my $koha_patron = $self->koha_patron;
229
    my $koha_patron = $self->koha_patron;
206
    if (my $auth_token = $koha_patron->overdrive_auth_token) {
230
    if (my $auth_token = $koha_patron->overdrive_auth_token) {
207
        my ($access_token, $access_token_type, $new_auth_token)
231
        my ($access_token, $access_token_type, $new_auth_token)
208
          = $self->client->auth_by_token($auth_token);
232
          = $self->client->make_access_token_request();
209
        $self->set_token_in_koha_session($access_token, $access_token_type);
233
        $self->set_token_in_koha_session($access_token, $access_token_type);
210
        $koha_patron->set({overdrive_auth_token => $new_auth_token})->store;
234
        $koha_patron->set({overdrive_auth_token => $new_auth_token})->store;
211
        return $access_token;
235
        return $access_token;
(-)a/admin/overdrive.pl (-1 lines)
Lines 30-36 my $input = CGI->new; Link Here
30
my @branchcodes   = $input->multi_param('branchcode');
30
my @branchcodes   = $input->multi_param('branchcode');
31
my @authnames     = $input->multi_param('authname');
31
my @authnames     = $input->multi_param('authname');
32
my $op            = $input->param('op');
32
my $op            = $input->param('op');
33
my @messages;
34
33
35
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {   template_name   => 'admin/overdrive.tt',
35
    {   template_name   => 'admin/overdrive.tt',
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt (-1 / +2 lines)
Lines 63-68 Link Here
63
[% Asset.js("js/overdrive.js") %]
63
[% Asset.js("js/overdrive.js") %]
64
[% Asset.js("lib/jquery/plugins/jquery.rating.js") %]
64
[% Asset.js("lib/jquery/plugins/jquery.rating.js") %]
65
<script>
65
<script>
66
var OD_password_required = [% IF Koha.Preference('OverDrivePasswordRequired') %]1[% ELSE %]0[% END %];
66
var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) |html %]";
67
var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) |html %]";
67
var results_per_page = [% OPACnumSearchResults %];
68
var results_per_page = [% OPACnumSearchResults %];
68
69
Lines 187-193 $( document ).ready( function() { Link Here
187
    [% IF ( overdrive_error ) %]
188
    [% IF ( overdrive_error ) %]
188
    KOHA.OverDriveCirculation.display_error("#breadcrumbs", "[% overdrive_error.dquote %]");
189
    KOHA.OverDriveCirculation.display_error("#breadcrumbs", "[% overdrive_error.dquote %]");
189
    [% END %]
190
    [% END %]
190
    [% IF ( loggedinusername and OverDriveCirculation ) %]
191
    [% IF ( loggedinusername and Koha.Preference('OverDriveCirculation') ) %]
191
    KOHA.OverDriveCirculation.with_account_details("#breadcrumbs", function() {
192
    KOHA.OverDriveCirculation.with_account_details("#breadcrumbs", function() {
192
        search( 0 );
193
        search( 0 );
193
    });
194
    });
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt (+1 lines)
Lines 1035-1040 Link Here
1035
    [% IF Koha.Preference('OverDriveCirculation') %]
1035
    [% IF Koha.Preference('OverDriveCirculation') %]
1036
    [% Asset.js("js/overdrive.js") %]
1036
    [% Asset.js("js/overdrive.js") %]
1037
    <script>
1037
    <script>
1038
    var OD_password_required = [% IF Koha.Preference('OverDrivePasswordRequired') %]1[% ELSE %]0[% END %];
1038
    $(document).ready(function() {
1039
    $(document).ready(function() {
1039
        [% IF ( overdrive_error ) %]
1040
        [% IF ( overdrive_error ) %]
1040
            KOHA.OverDriveCirculation.display_error("#opac-user-overdrive", "[% overdrive_error.dquote %]");
1041
            KOHA.OverDriveCirculation.display_error("#opac-user-overdrive", "[% overdrive_error.dquote %]");
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js (-5 / +11 lines)
Lines 71-77 KOHA.OverDriveCirculation = new function() { Link Here
71
    var login_link = $('<a href="#">')
71
    var login_link = $('<a href="#">')
72
        .click(function(e) {
72
        .click(function(e) {
73
            e.preventDefault();
73
            e.preventDefault();
74
            login(window.open());
74
            var passwd = OD_password_required ? prompt("Please enter your password") : "";
75
            login(passwd);
75
        })
76
        })
76
        .text(_("Login to OverDrive account"));
77
        .text(_("Login to OverDrive account"));
77
    var login_div = $('<div class="overdrive-login">').append(login_link);
78
    var login_div = $('<div class="overdrive-login">').append(login_link);
Lines 192-202 KOHA.OverDriveCirculation = new function() { Link Here
192
        });
193
        });
193
    }
194
    }
194
195
195
    function login(w) {
196
    function login(p) {
196
        svc_ajax('get', { action: "login" }, function(data) {
197
        svc_ajax('get', { action: "login", password: p }, function(data) {
197
            details = null;
198
            details = null;
198
            if (data.login_url) {
199
            if( data.login_success ){
199
                w.location = data.login_url;
200
                $(login_div).detach();
201
                if( $("#overdrive-results-page").length > 0 ){
202
                    location.reload();
203
                } else {
204
                KOHA.OverDriveCirculation.display_account_details( $("#opac-user-overdrive") );
205
                }
200
            }
206
            }
201
        });
207
        });
202
    }
208
    }
(-)a/opac/svc/overdrive (-2 / +9 lines)
Lines 24-29 use JSON qw(encode_json); Link Here
24
use C4::Auth qw(checkauth);
24
use C4::Auth qw(checkauth);
25
use C4::Output;
25
use C4::Output;
26
use Koha::Logger;
26
use Koha::Logger;
27
use Koha::Patrons;
28
use Koha::Library::OverDriveInfos;
27
use Koha::ExternalContent::OverDrive;
29
use Koha::ExternalContent::OverDrive;
28
30
29
my $logger = Koha::Logger->get({ interface => 'opac' });
31
my $logger = Koha::Logger->get({ interface => 'opac' });
Lines 43-49 local $@; Link Here
43
eval {
45
eval {
44
        {
46
        {
45
            $action eq 'login' && do {
47
            $action eq 'login' && do {
46
                $data{login_url} = $od->auth_url($page_url);
48
                my $password = $cgi->param("password") // "" ;
49
                my $patron = Koha::Patrons->find({ userid => $user });
50
                my $branch_info = Koha::Library::OverDriveInfos->find( $patron->branchcode ) if $patron;
51
                my $branch_authname = $branch_info->authname if $branch_info;
52
                my $authname = $branch_authname || C4::Context->preference('OverDriveAuthname');
53
                $od->auth_by_userid($user, $password,C4::Context->preference('OverDriveWebsiteID'),$authname);
54
                $data{login_success} = 1;
47
                last;
55
                last;
48
            };
56
            };
49
57
50
- 

Return to bug 21082